简体   繁体   English

在Maven多模块项目中更新版本

[英]Updating the versions in a Maven multi-module project

I have Maven multi-module project and I would like to update the development versions to a given value using a script. 我有Maven多模块项目,我想使用脚本将开发版本更新为给定值。 The aggregator POM is only an aggregator and the children do not inherit from it. 聚合器POM只是一个聚合器,子代不会从其继承。 This is important because the artifacts all inherit from other POM files. 这很重要,因为所有工件都从其他POM文件继承。 Here is my structure 这是我的结构

aggregator/
--projectA
--projectB

Also, projectB has a Maven dependency on projectA . 此外, projectB有一个Maven的依赖projectA

First I tried: 首先,我尝试了:

mvn -DnewVersion=0.28-SNAPSHOT -DupdateMatchingVersions=true versions:set

It only updated the aggregator project's version. 它仅更新了aggregator项目的版本。

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. 如果我运行Maven发行过程,它将在发行版本构建后正确更新projectBprojectA的依赖关系,以使用新的开发版本。 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 . 但是它没有更新projectB的扶养版本projectA

What is a simple way to update all the development versions in my project, including projectB 's dependency on projectA ? 更新项目中所有开发版本(包括projectBprojectA的依赖)的简单方法是什么?

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. versions:set旨在更新针对...执行的pom版本,即反应堆的根。

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. 当您同时指定了/project/parent/version /project/version ,但“偶然地”使用相同的值时,版本插件会假定这两个版本只是偶然地相同,因此当更新时,不会更新子项目的版本。父版本正在更新。 updateMatchingVersions tells the plugin to assume that it us not an accident and that the child should be in lock step. updateMatchingVersions告诉插件假定我们不是偶然的,孩子应该处于锁定状态。

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) 如果您仅指定/project/parent/version而未指定项目版本,因此依赖于继承,则插件会将子项目添加到版本更改列表中(并因此再次循环遍历所有项目,以确保捕获任何其他项目所需的更改)

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... 这是因为,如果父目录包含引用所调用项目的聚合器pom,则versions:set将尝试“增长”反应堆...

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; 我发现了同样的问题,然后克隆了版本插件代码,然后发现如果将gropuId,artifcatId,oldVersion值设置为*即可解决问题; like this : 像这样 :

mvn versions:set -DnewVersion=xxx -DgroupId=* -DartifactId=* -DoldVersion=* 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM