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