2011-09-30 140 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>