18

After finally getting tired of maven release plugin I deceided to move on to something more simpler.

I have a project, with a couple of modules.

When I do

mvn versions:set -DnewVersion=1.0.2-SNAPSHOT

it just changes the parent and skips all child modules?

what am I doing wrong? do I need to set another parameter as well?

7
  • Can you please post the pom.xml?
    – Behe
    Jan 26, 2013 at 12:35
  • 3
    have a shot mvn versions:update-child-modules
    – farmer1992
    Jan 26, 2013 at 13:47
  • The parent pom and child modules are using the <parent> tag, each pointing to different parents to inherit some code generation and what not. I will post a modified pom.xml as i cannot post the acutal. Could it be the parent tag causing this behaviour?
    – User123456
    Jan 26, 2013 at 19:42
  • I tried the 'mvn versions:update-child-modules' it skips the children and says they are up to date.
    – User123456
    Jan 26, 2013 at 22:02
  • 2
    I experienced this behavior when child module had parent which was not the base module. Other child modules which had base module as parent, were updating without any issues. Jan 27, 2013 at 20:39

7 Answers 7

19

I had the same problem of submodules referencing external parents.

If the child's parent version matches the parent's local version, then it updates the versions of the parent and child (it might say SKIPPED but still work, bizarrely). If they don't match then it seems to only update the parent's version and update the children to point to the new parent, it doesn't change the children's versions at all.

Finally i found that wildcards could resolve this problem (requires a new'ish version of the versions plugin):

mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=1.5.0a   -DartifactId=*  -DgroupId=*
3
  • The wildcard solved my multi-module problem where one of the modules declared in the root POM was defined as a standalone module with its POM not referencing any parent POM but only having its sub-modules, either also standalone or referencing the parent. It took me a while to find this answer after trying some other suggestions!
    – RZet
    Apr 11, 2016 at 18:00
  • This answer deserves more upvoting. What is happening is that the maven plugin is defaulting the artifact id to current aggregator's artifact id. Resulting in the aggregator submodules not being updated. Thanks for the tip!
    – Rasha
    Sep 19, 2016 at 12:13
  • for me it was also necessary to specify -DoldVersion=... Jan 11 at 10:22
8

Alternatively you can also use the processAllModules parameter.

$ mvn versions:set -DnewVersion=2.0.0 -DprocessAllModules
3

If you're like me with a project whose child modules don't match the parent's version, another option is to adjust them to match first:

$ mvn versions:update-child-modules

then versions:set (and versions:replace-snapshot etc.) will now work as expected, without needing a newer version of the plugin :)

$ mvn versions:set -DnewVersion=1.0.2-SNAPSHOT
2

I'm assuming that your project structure is like this:

parent/pom.xml
child/pom.xml

Then you have to run mvn versions:set -DnewVersion=1.0.2-SNAPSHOT from parent/ directory.

1
  • The tricky part is that I have a Master pom.xml as well (whose packaging is 'pom') that defines the submodules. In this case, YOU ARE STILL CORRECT, and I had to target my 'parent/pom.xml' as you mentioned. Also, FWIW, instead of executing from parent/, you can alternatively add the parameter -f parent/pom.xml, and that works quite nicely too.
    – Cody S
    Apr 10, 2014 at 19:17
1

If anyone searching for an answer, below command worked like a charm for me

mvn release:update-versions -DdevelopmentVersion=4.4.0-SNAPSHOT
1
  • This will only work for setting SNAPSHOT versions.
    – kopfarzt
    Feb 13 at 10:24
0

Maybe is because you don't declare the plugin in parent pom in Plugin Management. If you want to propagate the plugin to the childs you have to declare in Plugin Management Section.

See: http://maven.apache.org/pom.html#Plugin_Management

0

I eventually ran mvn -X to discover one of my child poms was saved in UTF-8 BOM encoding:

[DEBUG] Could not parse child-project\pom.xml java.io.IOException: only whitespace content allowed before start tag and not \uef (position: START_DOCUMENT seen \uef... @1:1) at org.codehaus.mojo.versions.api.PomHelper.getRawModel (PomHelper.java:116)

The Exception was 'hidden' in DEBUG logging.

I re-saved it using UTF-8 encoding, and it worked.

(Encountered with Maven 3.5.4 / Versions-Maven-Plugin 2.7)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.