【问题标题】:Maven POM dependency management with submodules带有子模块的 Maven POM 依赖管理
【发布时间】:2012-07-19 16:04:10
【问题描述】:

我有这两个 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 管理的依赖,而在Child 中省略了版本?为什么在对从聚合这些模块的父级继承的子模块使用dependencyManagment 时必须指定版本? 也许有一些建议?

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

【问题讨论】:

    标签: maven inheritance dependencies pom.xml


    【解决方案1】:

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

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

    • 子模块的聚合和
    • 作为将这个模块指定为父级的模块的父级

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

    这里有一些more details

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-16
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 2011-10-14
      • 1970-01-01
      • 2018-08-14
      相关资源
      最近更新 更多