2012-07-20 84 views
1

我有这两个文件POM:与子模块的Maven POM依赖管理

1)家长的pom.xml

...

<modules> 
    <module>web-module</module> 
    <module>interface-module</module> 
</modules> 
<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}.${project.artifactId}</groupId> 
      <artifactId>interface-module</artifactId> 
      <version>${project.version}</version> 
      <type>ejb</type> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

2)儿童的pom.xml

<dependencies> 
    <dependency> 
     <groupId>${project.parent.groupId}.${project.parent.artifactId}</groupId> 
     <artifactId>interface-module</artifactId> 
     <version>${project.version}</version> 
     <type>ejb</type> 
    </dependency> 
</dependencies> 

问题是:

为什么它无法解决由parent dependencyManagment管理的依赖关系,在Child中省略了版本?为什么我必须指定版本,而将dependencyManagment用于从正在聚合这些模块的Parent继承的子模块? 也许一些建议?

UPD: 原来,当儿童的groupId改变存在此行为,而不是被继承自父一... 基本上我有2子模块的家长之一,他们都是儿童父母之一。 当我更改Child模块中的groupId时,它会要求我在依赖管理期间指定版本,这有点奇怪。 任何想法,为什么maven是这样的?

回答

2

父项不会传递给子模块,这意味着您必须在子模块中声明父项。

此外,需要注意的是在一个模块中做两件事情:

  • 子模块的聚集和
  • 充当模块父母指定这一个父

这是通常可以,但是在某些时候,如果您的设置稍微复杂一些,您可能会遇到循环依赖或类似问题。只要你知道问题,你应该没问题。

这里有一些more details