0

它类似于Maven: Non-resolvable parent POM,但不一样。Maven:来自其他模块的不可解析的进口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

子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范围。
  • 我想尝试从module3移动import范围dependencies声明父模块,但它没有抱怨圆依赖

如何建立/加载孤独的子模块module3,或者是还有什么通过其他方式将多个子模块拆分为多个子模块dependencyManagement

+1

可能重复的[Maven模块+构建单个特定模块](http://stackoverflow.com/questions/1114026/maven-modules-building-a-single-specific-module) – Tunaki

+0

@Tunaki感谢您的信息,它使用命令行'mvn -pl module3 -am'工作,但实际上我想从其他一些实用程序(比如“jetbrains IDEA的运行生命周期”/“使用ant integration(maven-ant)”)加载子模块pom到加载依赖性“,对这些情况没有更好的支持。也许我必须将所有'dependencyManagements'移动到父pom –

回答

0

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

但是,如果你在模块3内工作,它不知道module1是项目的同级模块。

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

+0

这就是为什么我尝试使用'systemPath'但是发现maven不支持这种类型的导入 –

+0

@WilliamLeung转到您的项目的根级别进行'mvn install' 。之后使用'mvn -pl ...'永远不会更改到文件夹中...并且systemPath将永远不会工作.... – khmarbaise