Updating the versions in a Maven multi-module project

a 夏天 提交于 2019-12-10 14:44:58

问题


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?


回答1:


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




回答2:


# 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



回答3:


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=* 


来源:https://stackoverflow.com/questions/16865743/updating-the-versions-in-a-maven-multi-module-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!