It is about Maven POM's
If i would like to have the Version of my Parent also to be the Version of my Dependencies i must set a Property thats value is ${project.parent.version}.
The Problem then happen when a Child of my Main POM (Which has the ${project.parent.version} Property inside of it because it's Parent it some Project I don't Administrate) recalculate the property and think that the value of the created Property is now the version of my Main POM.
--SuperParent (not in my Administration) | Version = 1.2.3
----MainPom | Version = 1.0.0 | Property <test>${project.parent.version}</test> -> 1.2.3
------Child Pom | Version 1.0.0 | Property ${test} is now 1.0.0
<project>
<!-- Super Pom -->
 <groupId>groupId</groupId>
    <artifactId>artifactId</artifactId>
    <version>1.2.3</version>
</project>
<project>
<!-- MainPom -->
    <groupId>othergroupId</groupId>
    <artifactId>otherartifactId</artifactId>
    <version>1.0.0</version>
    <parent>
         <groupId>groupId</groupId>
         <artifactId>artifactId</artifactId>
         <version>1.2.3</version>
     </parent>
     <properties>
     <dependency.version>${project.parent.version}</dependency.version>
     </properties>
     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>dependencyGroupId<groupId>
                <artifactId>dependency</artifactId>
                <version>${dependency.version}</version>
            </dependency>
        </dependencies>
     </dependencyManagement>
</project>
<project>
<!-- ChildPom -->
    <groupId>childGroupId</groupId>
    <artifactId>childArtifactId</artifactId>
    <version>1.0.0</version>
    <parent>
         <groupId>othergroupId</groupId>
         <artifactId>otherartifactId</artifactId>
         <version>1.0.0</version>
     </parent>
        <dependencies>
            <dependency>
                <groupId>dependencyGroupId<groupId>
                <artifactId>dependency</artifactId>
            </dependency>
        </dependencies>
</project>
In the End is the Property ${dependency.version} in the Child Pom 1.0.0 instead of 1.2.3. Is this a wanted behavior of Maven? And what could I to do make it work?
Things that can't be changed:
Maven first process inheritance to build the effective pom and then process variables expansion.
In others words, the parent and child pom contents are processed as a single merged file for each child pom. So when your child pom is being processed the ${project.parent.version} is 1.0.0, not 1.2.3.
I couldn't find a way to reference the "grandparent" of a pom, so it seems that the only solution is to put the version as a static number both in the parent.version and properties.dependency.version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With