Java – How to use versions-maven-plugin to set child module versions

javamavenversion

I have a multi-module project with a common parent pom to all modules and an aggregator/build pom. I am trying to use the maven-versions-plugin to update/set the versions of all my modules, but it keeps skipping the child modules.

Project layout:
– common/pom.xml (build pom)
– common/superpom/pom.xml (parent pom)
– module1/pom.xml (module1 pom)
– module2/pom.xml (module2 pom)

common/pom.xml:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.bic</groupId>
    <artifactId>builder</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Builder</name>

    <modules>
        <module>../module1</module>

        <!-- POM Component Versionning -->
        <module>../module2</module>
    </modules>
<build>
    <plugins>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.1</version>
        </plugin>

    </plugins>
</build>
</project>

I have tried adding the plugin to the build pom (common/pom.xml) and then calling:

mvn versions:set -DnewVersion=999999

Maven lists all the props it found in the child modules, so I know it is parsing them all properly:

Props: {project.version=50, project.parent.version=1.0-SNAPSHOT, project.parent.groupId=com.bic, project.artifactId=module1, project.groupId=com.bic, project.parent.artifactId=common}
Props: {project.version=50, project.parent.version=1.0-SNAPSHOT, project.parent.groupId=com.bic, project.artifactId=module2, project.groupId=com.bic, project.parent.artifactId=common}

but it doesn't actually update the versions of any of the module poms, which is what I am looking to do.

[INFO] Reactor Summary:
[INFO]
[INFO] Module1 ........................................ SKIPPED
[INFO] Module2 ........................................ SKIPPED
[INFO] Builder ........................................ SUCCESS [  2.037 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.975 s
[INFO] Finished at: 2015-01-26T11:48:11-05:00
[INFO] Final Memory: 24M/44M
[INFO] ------------------------------------------------------------------------

And the update-child-modules goal doesn't allow me to explictly set a version number for the child modules.

Am I using the plugin incorrectly?

Best Answer

Couldn't figure out how to do it using the versions-maven-plugin directly, so I ended up doing it manually.

find . -name "pom.xml" -exec mvn versions:set -DnewVersion=1.0.3-SNAPSHOT -f {} \;

This ended up finding all the poms of my child modules and updating the version number in each. Definitely slower than using the plugin on the parent as it was designed to be done, but functional.