[英]Why Maven Versions Plugin (versions:use-latest-versions) not updating/changing -SNAPSHOT version to release (none -SNAPSHOT version)?
I am using the Version Maven Plugin plugin use-latest-versions functionality to update groupID=com.example* internal dependency versions to the latest version. 我正在使用Version Maven插件插件使用最新版本功能将groupID = com.example *内部依赖版本更新到最新版本。 This is executed as part of our CI system using Jenkins. 这是使用Jenkins作为CI系统的一部分执行的。
When developers start working on a new feature they branch the code, work on the branch and when the new feature is implemented (or partially implemented) the code is merged back to trunk (usually multiple times a week). 当开发人员开始处理新功能时,他们会分支代码,在分支上工作,当新功能实现(或部分实现)时,代码将合并回主干(通常每周多次)。
Branches version update: 分支版本更新:
mvn -P snapshot -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false -DallowSnapshots=true ...
用于更新版本的命令: mvn -P snapshot -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false -DallowSnapshots=true ...
Trunk version update: 中继版本更新:
mvn -P production -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false ...
用于更新版本的命令: mvn -P production -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false ...
Sometimes branch builds update com.example* dependency versions to "...-SNAPSHOT" version (this is normal because libs-snapshot Artifactory repo is used as the dependency repository which can have -SNAPSHOT dependency versions). 有时分支构建会将com.example *依赖版本更新为“...- SNAPSHOT”版本(这是正常的,因为libs-snapshot Artifactory repo用作可以具有-SNAPSHOT依赖版本的依赖库)。 These version updates are checked back to source control (svn). 这些版本更新将检查回源代码控制(svn)。
When the code (including the pom.xml version update changes) are merged back from branches to trunk and the trunk build is executed, all com.example* internal dependency versions should be changed/updated to the latest release versions. 当代码(包括pom.xml版本更新更改)从分支合并回主干并执行主干构建时,所有com.example *内部依赖版本都应更改/更新为最新版本。 But because of some reason when dependency versions have "-SNAPSHOT" in it versions:use-latest-versions is not changing/updating the version to the latest release (none -SNAPSHOT) version. 但由于某些原因,依赖版本在其版本中具有“-SNAPSHOT” :use-latest-versions不会将版本更改/更新为最新版本(无-SNAPSHOT)版本。
Example: 例:
Artifactory repos have the flowing versions: Artifactory repos有流动的版本:
Making myApp branches build will get dependency versions from libs-snapshot and update com.example:myLib version to 1.1.11-SNAPSHOT and check this update back to SVN 使myApp分支构建将从libs-snapshot获取依赖版本并将com.example:myLib版本更新为1.1.11-SNAPSHOT并将此更新检查回SVN
...
<dependency>
<groupId>com.example</groupId>
<artifactId>myLib</artifactId>
<version>1.1.11-SNAPSHOT</version>
</dependency>
...
Merging code back to trunk including the above dependency version changes and running the trunk build (including version update) mvn -P production -B versions:use-latest-versions...
does not change the com.example:myLib version to 1.1.12 将代码合并回主干包括上述依赖版本更改并运行主干版本(包括版本更新) mvn -P production -B versions:use-latest-versions...
不会将com.example:myLib版本更改为1.1。 12
Artifactory configuration: 工具配置:
pom.xml configuration: pom.xml配置:
...
<profiles>
<profile>
<id>snapshot</id>
<distributionManagement>
<repository>
<id>libs-snapshot-local</id>
<name>Internal Applications Snapshot Repository</name>
<url>http://example.com/artifactory/libs-snapshot-local</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>libs-snapshot</id>
<name>libs-snapshot</name>
<url>http://example.com/artifactory/libs-snapshot</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>libs-release</id>
<name>libs-release</name>
<url>http://example.com/artifactory/libs-release</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<build>
...
</build>
</profile>
<profile>
<id>production</id>
<distributionManagement>
<repository>
<id>libs-release-local</id>
<name>Internal Applications Snapshot Repository</name>
<!-- Artifacts are promoted to libs-release-local not deployed directly -->
<url>http://example.com/artifactory/libs-snapshot-local</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>libs-release</id>
<name>libs-release</name>
<url>http://example.com/artifactory/libs-release</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<build>
...
</build>
</profile>
</profiles>
... ...
You should make sure you are using the latest versions plugin ( 2.3
). 您应该确保使用的是最新版本的插件( 2.3
)。 I believe 2.3
fixed some issues (that being said it is still an incredibly buggy plugin). 我相信2.3
修复了一些问题 (据说它仍然是一个令人难以置信的错误插件)。
The other issue I have found with the version plugin is combining with other version goals or even other maven goals. 我在版本插件中发现的另一个问题是与其他版本目标甚至其他maven目标相结合。 Don't do that. 不要那样做。 For example your code above you are running versions:use-latest-versions versions:update-properties
at the same time. 例如,您上面的代码正在运行versions:use-latest-versions versions:update-properties
。 Instead execute mvn
once for each one of those goal. 而是为每个目标执行一次mvn
。 Yes this is a pain and slows down the build process but I found it far more reliable particularly if you use versions:update-parent (2.3 may have fixed these issues though). 是的,这是一个痛苦,并减慢了构建过程,但我发现它更可靠, 特别是如果您使用版本:更新 - 父 (2.3可能已修复这些问题)。
I also think excludeReactor
is generally broken . 我也认为excludeReactor
一般都被打破了 。 If you are running a version update on aggregate project I don't recommend it. 如果您在聚合项目上运行版本更新,我不建议它。 Instead go to each submodule and run the command. 而是转到每个子模块并运行命令。
You have to do 2 steps: 你必须做两个步骤:
mvn versions:use-releases
(This will change all SNAPSHOT to release versions) mvn versions:use-releases
(这会将所有SNAPSHOT更改为发布版本) mvn versions:use-latest-release
(This will change the current release version to the latest available release version) mvn versions:use-latest-release
(这会将当前版本更改为最新的可用版本) I think there is an error in the documentation. 我认为文档中有错误。
http://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html http://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html
The documentation: 文件:
versions:use-latest-releases
searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version. versions:use-latest-releases
在pom中搜索所有非SNAPSHOT版本,这些版本是较新版本,并将其替换为最新版本。
Conflicts with the goal matrix below. 与下面的目标矩阵冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.