【发布时间】:2017-01-12 20:20:16
【问题描述】:
类似于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 使用dependencyManagement 定义了一些dependencies
子 pom: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
但如果我在子模块中运行构建,它会失败
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
我尝试过的
- 我会尝试使用
systemPath,但import范围不支持它。 - 我会尝试将
import范围dependencies声明从module3移动到父模块,但它未能抱怨循环依赖
如何构建/加载单独的子模块module3,或者有没有其他方法可以将大量的dependencyManagements 拆分为多个子模块?
【问题讨论】:
-
@Tunaki 感谢您提供的信息,它是使用命令行
mvn -pl module3 -am工作的,但实际上我想从其他一些实用程序加载子模块 pom,例如“从 jetbrains IDEA 运行生命周期”/“使用 ant 集成 (maven-ant) 加载依赖项”,对于这些情况没有更好的支持。也许我不得不将所有dependencyManagements移动到父 pom
标签: maven dependency-management circular-dependency multi-module