Maven:来自其他模块的不可解析的导入POM

时间:2016-09-05 12:48:34

标签: maven dependency-management circular-dependency multi-module

有些像Maven: Non-resolvable parent POM但不一样。

我有父母pom

<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
</modules>

module1使用dependencies

定义了一些dependencyManagement

儿童游戏:module3/pom.xml尝试导入module1

<parent>
    <artifactId>group</artifactId>
    <groupId>parent</groupId>
    <version>SNAPSHOT</version>
    <relativePath>../</relativePath>
</parent>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>group</groupId>
      <artifactId>module1</artifactId>
      <version>SNAPSHOT</version>
      <scope>import</scope>
      <type>pom</type>
      <!--
      <systemPath>../module1</systemPath>
      -->
    </dependency>
  </dependencies>
</dependencyManagement>

如果我尝试构建父级,则可以

mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:

... ...

[INFO] parent ............................................ SUCCESS [0.128s]
[INFO] module1 ........................................... SUCCESS [0.011s]
[INFO] module2 ........................................... SUCCESS [0.009s]
[INFO] module3 ........................................... SUCCESS [0.009s]
... ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

但是如果我在子模块中运行build,它就会失败

mvn validate
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project group:module3:SNAPSHOT (/path-tp/project/module3/pom.xml) has 5 errors
[ERROR]     Non-resolvable import POM: Failure to find group:module1:pom:SNAPSHOT in https://repo1.maven.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ line 22, column 19 -> [Help 2]
... ...
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

我尝试了什么

  • 我尝试使用systemPathimport范围不支持。
  • 我尝试将import范围dependencies声明从module3移到父模块,但它没有抱怨循环依赖

如何构建/加载单独的子模块module3,还是有其他方法可以将大量的dependencyManagement拆分为多个子模块?

1 个答案:

答案 0 :(得分:0)

在父级别工作时,Maven能够解决模块之间的依赖关系。

但是如果你在模块3中工作,它不知道module1是项目的兄弟模块。

如果您想直接在模块3内部工作,则需要先安装模块1。