使用 mvn versions:update-parent 时如何强制使用任意父版本?

How to force an arbitrary parent version when using mvn versions:update-parent?

(改写问题以便更好地理解) 为了详细说明我的问题不够详细,这些是我遇到的以下情况: 项目:A 和 B。A 的根 pom 是项目 B 的父级。

由于我们的发布过程受到一些限制(这是为了提供一些当前上下文,但这不应被视为规避手头问题的主要驱动力),我需要更改两个项目的版本。

如果我更改 A 的版本,然后更改 B 的版本,我会收到以下错误消息:

mvn versions:update-parent -DallowSnapshots -DgenerateBackupPoms=false -DparentVersion="6.4.1-SNAPSHOT" 
[WARNING] Not updating version: could not resolve any versions

如果我更改 A 的版本,请在 A 上调用 mvn clean install(我可以接受,尽管我希望能够在脚本中一次更改所有项目的版本和父级, 没有中间的、可能失败的构建),那么 B 上的上述命令有效,但前提是指定的父版本是最新可用的。否则我得到:

[INFO] Current version of parentGroup:parentArtifact:pom:7.0.12 is the latest.

这意味着我不能使用 mvn versions:update-parent 命令更改维护分支上的父版本。

有没有办法让 mvn versions:update-parent 遵守所需的父版本? (不管它是否可以在本地找到,在 nexus 存储库中还是根本找不到)


编辑:附加信息 -X(删除了不相关的部分,重点是我的)

[DEBUG] Configuring mojo 'org.codehaus.mojo:versions-maven-plugin:2.5:update-parent' with basic configurator -->
[DEBUG]   (f) allowSnapshots = true
[DEBUG]   (f) generateBackupPoms = false
(...)
[DEBUG]   (f) parentVersion = 7.0.11
[DEBUG] Determining update check for artifact groupId:artifactIdProjectA (C:\Users\donckels\.m2\repository\.......\artifactIdProjectA\maven-metadata-....-repository.xml) from ....-repository (http://..../nexus/content/groups/public)
(....)
[DEBUG] Searching for ....-repository.maven-metadata-....-repository.xml.lastUpdated in resolution tracking file.
[DEBUG] Reading resolution-state from: C:\Users\donckels\.m2\repository\.....\artifactIdProjectA\resolver-status.properties
(....)
[DEBUG] Proposal is to update from 7.0.12 to 7.0.12
[INFO] Current version of groupId:artifactIdProjectA:pom:7.0.12 is the latest.

尽管我指定了 7.0.11,但它的结尾是:

[DEBUG] Proposal is to update from 7.0.12 to 7.0.12

because the version I want to use is a version which is either locally built

然后构建父级的步骤不应该只是 mvn clean build,而是 mvn clean install:这会将工件缓存在 Jenkins 代理本地 Maven 缓存中。

either a version which will be built later

那么你的工作应该有一个初步的步骤来构建和安装那个新的父版本,在你当前的步骤调用 mvn versions:update-parent.

之前

正如 OP 评论的那样:

The stumble point was the set of square brackets around the version, in addition to the "built before" requirement.
Without those square brackets, the version was ignored if it wasn't the latest.

在“Version Range Specification”查看更多信息

[1.0]   x == 1.0

如果之前已经构建了父版本,则此语法(版本号周围带有方括号)允许强制使用不是最新的版本:

mvn versions:update-parent -DallowSnapshots -DgenerateBackupPoms=false -DparentVersion="[7.0.11]" 

但是父 必须 在 maven 进行更新之前构建。否则它将忽略指定的版本。