2011-09-30 137 views
42

我有我的Maven項目設置爲1個外殼項目和4個子模塊。當我嘗試構建shell時。我得到:Maven:不可解析的父POM

[INFO] Scanning for projects... 
[ERROR] The build could not read 1 project -> [Help 1] 
[ERROR] 
[ERROR] The project module1:1.0_A0 (C:\module1\pom.xml) has 1 error 
[ERROR] Non-resolvable parent POM: Failure to find shell:pom:1.0_A0 in http://nyhub1.ny.ssmb.com:8081/nexus/content/repositories/JBoss/ was cached in the local repository, resolution will not be reattempted until the update interval of jboss has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help 2] 

如果我嘗試構建一個單獨的模塊,我得到相同的錯誤只替換模塊1,無論它是什麼模塊。

讓他們在他們的poms中引用父項。

<parent> 
    <artifactId>shell</artifactId> 
    <groupId>converter</groupId> 
    <version>1.0_A0</version> 
</parent> 

這裏是殼聚甲醛的相關部分:

僅供參考
<groupId>converter</groupId> 
<artifactId>shell</artifactId> 
<version>1.0_A0</version> 
<packaging>pom</packaging> 
<name>shell</name> 


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

回答

50

Maven的歡樂。

將模塊的相對路徑放到../pom.xml中解決。

parent元素有一個relativePath元素,您需要指向父級的目錄。它默認爲..

+11

是的。使用Maven需要你知道你做了什麼,試驗和錯誤不會讓你走得很遠。另一方面有幾個很好的參考。這是[one](http://www.sonatype.com/books/mvnref-book/reference/)。 –

+0

因此,您在''之下添加了這個' ..'? – octavian

+0

我指出它到我的relativePath值默認值maven放在那裏.. – Will

6

另一個原因也可能是父代工件來自無法從pom.xml訪問的存儲庫,通常是私有存儲庫。解決的辦法是提供pom.xml該資源庫:

<repositories> 
    <repository> 
     <id>internal-repo</id> 
     <name>internal repository</name> 
     <url>https://my/private/repo</url> 
     <layout>default</layout> 
     <releases> 
      <enabled>true</enabled> 
     </releases> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </repository> 
</repositories> 

在我的情況,問題變得更加複雜,由於到Eclipse:倉庫只在特殊型材(<profiles><profile><id>activate-private-repo</id><repositories>...)和Maven GUI在Eclipse活躍不允許通過Ctrl+Alt+P快捷方式設置此配置文件。

解決方案是臨時聲明倉庫外部配置文件(無條件),啓動Alt+F5 Maven更新項目,激活配置文件並將倉庫聲明放回配置文件。這是Eclipse錯誤,而不是Maven錯誤。

+0

同樣的情況!沒有添加到pom的私人回購。 – LoranceChen

10

也可以通過將正確的settings.xml文件放入~/.m2/目錄來解決。

+1

正是這樣解決了我的問題,謝謝!但不要把它放到某個目錄中,而是在Preferences - Maven - User Settings中指向Eclipse。 – Brain

1

如果你有兒童的POM正確的價值觀

GroupId 
ArtefactId 
Version 

在Eclipse中,例如,你可以搜索驗證: Eclipse: search parent pom

0

更換1.0_A0 與 $ {} project.version

運行mvn一次。這將下載所有必需的存儲庫。此步驟後,您可以切換回1.0_A0。

+0

只有當所需的父POM與子模塊的POM具有相同的版本時,這才起作用。這並非總是如此。 –

0

我在工作中遇到過類似的問題。

無依賴地構建父項目在.m2文件夾中創建parent_project.pom文件。

然後在父POM中添加子模塊並運行Maven構建。

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