Search code examples
mavenpom.xmlmaven-versions-plugin

Why doesn't Maven versions plugin update the locally defined property?


I am using the versions-maven-plugin and have several configurations in my top-level pom.xml for versions-maven-plugin:

<build>
    <pluginManagement>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.8.1</version>
            <configuration>
                <properties>
                    <property>
                        <name>magic-tool.version</name>
                    </property>
                </properties>
            </configuration>
        </plugin>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
        </plugin>
...
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <reportSets>
               <reportSet>
                    <reports>
                        <report>dependency-updates-report</report>
                        <report>plugin-updates-report</report>
                        <report>property-updates-report</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>

And also a property referring to an in-house repository "magic-tool":

<properties>
     <magic-tool.version>100</magic-tool.version>

The command in question is

mvn clean && mvn versions:update-properties versions:commit -N -U -DincludeProperties=magic-tool.version -DallowSnapshots=true -X

This is preferred to specifying the exact version as it will be used in TeamCity - and this command works perfectly in another app with a near identical pom.xml, and a perfectly identical and configuration!

However the output for non-functional app is

[DEBUG] lowerBoundArtifactVersion: 100
[DEBUG] Property ${magic-tool.version}: Current winner is: null
[INFO] Property ${magic-tool.version}: Leaving unchanged as 100

when magic-tool is on v102 in our repo, whilst our correctly working app outputs:

[DEBUG] Property ${magic-tool.version}: Set of valid available versions is [1, 2, 3, 4, 5, 6, 7... 95, 96, 97, 98, 99, 100, 101, 102]
[DEBUG] Property ${magic-tool.version}: Restricting results to null
[DEBUG] lowerBoundArtifactVersion: 101
[DEBUG] Property ${magic-tool.version}: Current winner is: 102
[DEBUG] Property ${magic-tool.version}: Searching reactor for a valid version...
[DEBUG] Property ${magic-tool.version}: Set of valid available versions from the reactor is []
[INFO] Updated ${magic-tool.version} from 100 to 102

How do I get the non-functional app to update this property magic-tool.version?


Solution

  • The answer was that the property went unused in non-functional > parent pom > dependencies but was used in functional app > parent pom > dependencies.

    The command is non-recursive so it is unaware that property magic-tool.version is used in non-functional app > child poms > dependencies.

    The solution is to actively use/define the property in dependencies in the top level pom (note that adding it to <dependencyManagement> did nothing).