maven-2pom.xmlmulti-moduleparent-pom

Parent Pom get version of Child Pom/dependency


I have a project like the following

mainProject - Multi Module Project structure:

pom.xml
newfolder/pom.xml

otherProject:

otherProject.pom.xml with mainProject.pom.xml as its parent pom and newFolder/pom.xml as a dependency.

see below:

mainProject pom.xml:

<groupId>test.test</groupId>
<artifactId>mainProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
    <module>newFolder</module>
</modules>
<dependency>
    <groupId>test.test</groupId>
    <artifactId>newFolder</artifactId>
    <version>${project.version}</version>
</dependency>

newfolder/pom.xml:

<groupId>test.test</groupId>
<artifactId>newFolder</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
    <groupId>test.test</groupId>
    <artifactId>mainProject/artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>   

otherProject:

<parent>
    <groupId>test.test</groupId>
    <artifactId>mainProject</artifactId>
    <version>1.0-SNAPSHOT/version>
</parent>
<dependency>
    <groupId>test.test</groupId>
    <artifactId>newFolder</artifactId>
</dependency>

The problem is when I try to build otherProject it cannot find the version of newfolder because it is not pulling in the version of the project that I built it is still looking for newfolder 1.0-SNAPSHOT

Any help would be great!


Solution

  • I was able to get the behavior I was hoping for by adding ${project.parent.version} to the parent pom dependency. example:

    <groupId>test.test</groupId>
    <artifactId>mainProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>newFolder</module>
    </modules>
    <dependency>
        <groupId>test.test</groupId>
        <artifactId>newFolder</artifactId>
        <version>${project.parent.version}</version>
    </dependency>