2014-09-22 98 views
1

我在管理继承的依赖关系时遇到问题。我有,在水平之上,我的“顶”级项目,拥有自己的pom.xml具有如何从父对象继承父对象到另一个父对象?

<dependencyManagement> 
     <dependencies> 
      <!-- Utils --> 
      <dependency> 
       <groupId>junit</groupId> 
       <artifactId>junit</artifactId> 
       <version>4.11</version> 
      </dependency> 
     </dependencies> 
</dependencyManagement> 

在另一边,我有我的“第二级”项目,该项目继承了顶级项目并且我想继承junit依赖关系:

<parent> 
     <artifactId>com.test</artifactId> 
     <groupId>top-level-class</groupId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

<dependencyManagement> 
     <dependencies> 
      <!-- Utils --> 
      <dependency> 
       <groupId>junit</groupId> 
       <artifactId>junit</artifactId> 
      </dependency> 
     </dependencies> 
</dependencyManagement> 

但是,这是捕获依赖项的版本。它说:“管理版本无法确定,工件管理在com.test.second-level-test:0.0.1-SNAPSHOT”

有没有人有任何关于如何解决这个问题的想法?问候

+1

只是删除它从孩子的POM的... – StackFlowed 2014-09-22 13:18:58

+0

你有没有宣布“第二级”项目为父母的模块? – geoand 2014-09-22 13:19:02

+0

我把它作为,因为我想要这些依赖项继承到另一个太阳项目。 – jscherman 2014-09-22 13:20:39

回答

4

你的第二级POM应该像这样(的依赖应该是直属项目):

 <project blabla> 
    <parent> 
     <artifactId>com.test</artifactId> 
     <groupId>top-level-class</groupId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    .... 

     <dependencies> 
      <!-- Utils --> 
      <dependency> 
       <groupId>junit</groupId> 
       <artifactId>junit</artifactId> 
      </dependency> 
     </dependencies> 
    ... 

    </project> 
+0

但通过这种方式,这个项目的太阳不会继承junit的依赖,是吗? – jscherman 2014-09-22 15:05:33