We run mvn versions:set -DnewVersion=x.x.x to update the version of our project. For some projects it updates the version in all pom.xml files except one or two. What are some reasons that this command wouldn't update all files?
There are some reasons. The parent is not correctly set in the childs. The childs have different versions as the parent or the other childs. The child is only part of the aggregator based on some profiles.
So you can try with:
mvn version:set -DnewVersion=3.6.0 -DoldVersion=* -DgroupId=* -DartifactId=*
This is explained at https://www.mojohaus.org/versions-maven-plugin/examples/setaggregator.html.
For more advice we would need the pom files.
Related
In a multi-module maven project to set versions in parent pom we need to execute:
mvn versions:set -DnewVersion=<version_to_set>
Then to update the version of the parent in the child modules we need to execute:
mvn -N versions:update-child-modules
The above two commands create files with name pom.xml.versionsBackup besides the original pom.xml. To commit the version update we need to execute:
mvn versions:commit
Which also deletes the pom.xml.versionsBackup file for the parent pom.xml, but not for the child modules.
How can we delete the pom.xml.versionsBackup files for the pom.xml of child modules?
I'm using the versions plugin to... set versions.
mvn versions:set -DnewVersion=XXXX
That work's great on aggregate project with declared modules
Now my question is how, in other maven project can I change the parent pom version ? I've placed high hopes in the versions:update-parent but I would like just to set the parent with the version i'm specifying regardless whether that version is deployed or not. Besides I can't get it to work. It never modifies the actual pom. Is there a way to do just that using a mvn plug-in ? Right now it's a manual pom.xml edit.
Thanks
Aa.
I usually use release plugin for that. It changes version of the parent and all the submodules:
mvn release:update-versions -DautoVersionSubmodules=true
Details are here:
http://maven.apache.org/maven-release/maven-release-plugin/examples/update-versions.html
I have Maven multi-module project and I would like to update the development versions to a given value using a script. The aggregator POM is only an aggregator and the children do not inherit from it. This is important because the artifacts all inherit from other POM files. Here is my structure
aggregator/
--projectA
--projectB
Also, projectB has a Maven dependency on projectA.
First I tried:
mvn -DnewVersion=0.28-SNAPSHOT -DupdateMatchingVersions=true versions:set
It only updated the aggregator project's version.
If I run the Maven release process, it correctly updates projectB's dependency on projectA to use the new development version after the release build. Because the release process handles this well, I thought that using the release plugin might solve my issue.
So I tried the following:
mvn -DdevelopmentVersion=0.28-SNAPSHOT -DautoVersionSubmodules=true --batch-mode release:update-versions
This updated all of my sub-projects correctly. However it did not update projectB's dependency version for projectA.
What is a simple way to update all the development versions in my project, including projectB's dependency on projectA?
You may have more luck with the release plugin but it may require some tweaking
versions:set is designed to update the version of the pom that it executes against... ie the root of the reactor.
If you follow it's conventions, then it will work... But you need to know its conventions.
When you have /project/parent/version and /project/version both specified but "accidentally" at the same value, the versions plugin assumes that the two versions are just accidentally the same, and so does not update the child project's version when the parent version is being updated. updateMatchingVersions tells the plugin to assume that it us not an accident and that the child should be in lock step.
If you only specify /project/parent/version and leave the project version unspecified, therefore relying on inheritance, the plugin will add the child project to the list of version changes (and hence loop through all the projects again to ensure it catches any additional required changes)
The versions plugin does not currently provide an option to force everything to the one version... Though that might be a good idea.
You can get what you want with three commands, eg
mvn versions:set -DnewVersion=...
cd projectA
mvn versions:set -DnewVersion=...
cd ../projectB
mvn versions:set -DnewVersion=...
This is because versions:set will attempt to "grow" the reactor if the parent directory contains an aggregator pom that references the invoked project...
In other words when you have a reactor with no common parent, versions assumes that the common version number is by accident, but it will pick up the intent from the wider reactor
# for each module into aggregator pom
for module in $(grep "\<module\>" pom.xml | sed 's/<\/module>//g' | sed 's/.*<module>//g' | sed 's/.*\///g')
do
# set the version of the module
# and update reference to this module into others modules
mvn versions:set -DgenerateBackupPoms=false -DartifactId=$module \
-DnewVersion=$newVersion -DupdateMatchingVersions=true
done
# set the version of the aggregator pom
mvn versions:set versions:commit -DnewVersion=$newVersion
i found your same problem ,then i clone versions plugin code , then I found if you set gropuId,artifcatId,oldVersion value tobe * will solve the problem;
like this :
mvn versions:set -DnewVersion=xxx -DgroupId=* -DartifactId=* -DoldVersion=*
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?
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=*
Alternatively you can also use the processAllModules parameter.
$ mvn versions:set -DnewVersion=2.0.0 -DprocessAllModules
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
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.
If anyone searching for an answer, below command worked like a charm for me
mvn release:update-versions -DdevelopmentVersion=4.4.0-SNAPSHOT
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
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)
Whenever I want to create a new version of my projects, I have to go in and edit the <version> tag in the POM files.
The projects are related, so they have the same version, most of the time.
Is it possible to just put the new version in some file, and have the POM regenerated when needed?
Thanks
The best thing in such situations is to use the release plugin which supports automatically changing the version in the pom and creating a tag/label in the appropriate VCS. There are two steps release:prepare and release:perform which can simply be combined.
A command like this:
mvn release:prepare release:prepare
will do all needed steps like making a tag in VCS, change pom's version and deploy the artifacts to your repository. But the prerequesite is having correct entries in the SCM area of your pom, correctly configured the distributionManagement etc.
If the project comprises of several modules which have the same version this sounds like using a multi-module build instead of separated projects which would solve the problem of changing the version manually.