在Maven多模块项目中更新版本 [英] Updating the versions in a Maven multi-module project

查看:183
本文介绍了在Maven多模块项目中更新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Maven多模块项目,我想使用脚本将开发版本更新为给定值.聚合器POM只是一个聚合器,子代不会从其继承.这很重要,因为所有工件都从其他POM文件继承.这是我的结构

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

此外,projectBprojectA具有Maven依赖关系.

Also, projectB has a Maven dependency on projectA.

首先,我尝试过:

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

它仅更新了aggregator项目的版本.

It only updated the aggregator project's version.

如果我运行Maven发行过程,它将在发行版本构建后正确更新projectBprojectA的依赖性,以使用新的开发版本.因为发行过程可以很好地解决此问题,所以我认为使用发行插件可以解决我的问题.

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

这样可以正确更新我的所有子项目.但是,它没有更新projectAprojectB依赖版本.

This updated all of my sub-projects correctly. However it did not update projectB's dependency version for projectA.

更新项目中所有开发版本(包括projectBprojectA的依赖)的简单方法是什么?

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

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.

当您同时指定了/project/parent/version /project/version,但偶然地"使用了相同的值时,版本插件会假定这两个版本只是偶然地相同,因此不会更新父版本正在更新时子项目的版本. updateMatchingVersions告诉插件假定我们不是偶然的,孩子应该处于锁定状态.

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.

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

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

这是因为如果父目录中包含引用所调用项目的聚合pom,则versions:set将尝试增长"反应堆...

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

这篇关于在Maven多模块项目中更新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆