1

我有这两个 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>

问题是:

为什么它无法解决由父依赖管理管理的依赖项,而子项中省略了版本?为什么在对从聚合这些模块的父级继承的子模块使用dependencyManagment 时必须指定版本?也许一些建议?

UPD:事实证明,当子项的 groupId 发生更改并且不是从父项继承的那个时,这种行为存在......基本上我有父项的 2 个子模块,它们都是父项的子项。当我更改子模块中的 groupId 时,它要求我在依赖管理期间指定版本,这有点奇怪。任何想法为什么 Maven 会那样做?

4

1 回答 1

2

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

另外,请注意您在一个模块中做两件事:

  • 子模块的聚合和
  • 充当指定此模块为父模块的父模块

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

这里有更多细节

于 2012-07-20T11:24:17.860 回答