Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use versions-maven-plugin to set child module versions?

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?

like image 690
Eric B. Avatar asked Jan 26 '15 16:01

Eric B.


3 Answers

A solution was introduced in version 2.5 of plugin versions-maven-plugin

mvn versions:set -DnewVersion=1.6-SNAPSHOT -DprocessAllModules=true

or if like me you need to force the version:

mvn org.codehaus.mojo:versions-maven-plugin:2.5:set -DnewVersion=1.6-SNAPSHOT -DprocessAllModules=true
like image 147
foch Avatar answered Oct 04 '22 13:10

foch


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.

like image 23
Eric B. Avatar answered Oct 04 '22 15:10

Eric B.


This is a little late to the party, but I just found the answer. You need to run the versions:set goal on the parent project directly. It will take care to scan for an aggregator POM nearby (probably only looks up one directory, but I am not positive), and will update the parent, aggregator, and all child modules just as you expect.

The root POM is the aggregator and lists parent, module1, and module2 as modules:

DANIJOH2-M-V0MA:test danijoh2$ ls
module1 module2 parent  pom.xml

The root aggregator POM, module1, and module2 all refer to parent/pom.xml as their parent POM. Move into the parent and run the versions:set goal:

DANIJOH2-M-V0MA:test danijoh2$ cd parent
DANIJOH2-M-V0MA:parent danijoh2$ ls
pom.xml

DANIJOH2-M-V0MA:parent danijoh2$ mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=1.0.0 -DgenerateBackupPoms=false
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- versions-maven-plugin:2.1:set (default-cli) @ parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /Users/danijoh2/Desktop/test
[INFO] Processing com.cisco.dan.test:parent
[INFO]     Updating project com.cisco.dan.test:parent
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] 
[INFO] Processing com.cisco.dan.test:aggregator
[INFO]     Updating parent com.cisco.dan.test:parent
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]     Updating project com.cisco.dan.test:aggregator
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] 
[INFO] Processing com.cisco.dan.test:module1
[INFO]     Updating parent com.cisco.dan.test:parent
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]     Updating project com.cisco.dan.test:module1
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] 
[INFO] Processing com.cisco.dan.test:module2
[INFO]     Updating parent com.cisco.dan.test:parent
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]     Updating project com.cisco.dan.test:module2
[INFO]         from version 1.0.0-SNAPSHOT to 1.0.0
like image 34
Daniel Johnson Avatar answered Oct 04 '22 13:10

Daniel Johnson