Maven POM dependency management with submodules

I've got these two pom files:

1) Parent 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) Child 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>

The question is:

Why it can't resolve the dependency being managed by parent dependencyManagment with version omitted in the Child? Why do I have to specify the version while using dependencyManagment for submodule that is inherited from the Parent that is aggregating these modules? Maybe some advice?

UPD: Turned out that this behavior exists when groupId of the Child is changed and is not the one that is inherited from the Parent... Basically I have 2 submodules of the Parent one and they both are children of the Parent one. When I change the groupId in the Child module then it asks me to specify the version during dependency management which is kinda strange. Any ideas why maven is acting like that?


Parent's are not passed on to submodules, meaning you'll have to declare the Parent also in the submodule.

Also, note that you are doing two things in one module:

  • Aggregation of submodules and
  • Acting as a parent for modules that specify this one as parent
  • This is usually ok, but at some point you might run into circular dependencies or similar problems if your setup gets a little more complex. As long as you know the problem, you should be fine.

    Here are some more details

    链接地址: http://www.djcxy.com/p/29704.html

    上一篇: 如何在Maven中的多个项目之间共享项目依赖关系?

    下一篇: Maven POM依赖管理与子模块