简体   繁体   English

为什么Maven Versions Plugin(版本:use-latest-versions)没有更新/更改-SNAPSHOT版本才能发布(无-SNAPSHOT版本)?

[英]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: 分支版本更新:

  • Using "snapshot" profile. 使用“快照”配置文件。 See below pom.xml snapshot profile configuration and Artifactory repo configuration 请参阅下面的pom.xml快照配置文件配置和Artifactory repo配置
  • Command used to update version: 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: 中继版本更新:

  • Using "production" profile. 使用“生产”配置文件。 See below pom.xml production profile configuration and Artifactory configuration 请参阅下面的pom.xml生产配置文件配置和Artifactory配置
  • Command used to update version: 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有流动的版本:

  • libs-snapshot has "com.example:myLib:1.1.10-SNAPSHOT", "com.example:myLib:1.1.11-SNAPSHOT" libs-snapshot有“com.example:myLib:1.1.10-SNAPSHOT”,“com.example:myLib:1.1.11-SNAPSHOT”
  • libs-release has "com.example:myLib:1.1.9", "com.example:myLib:1.1.12" libs-release有“com.example:myLib:1.1.9”,“com.example:myLib:1.1.12”

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: 工具配置:

  • Local repos: libs-snapshot-local (development repository); 本地存储库:libs-snapshot-local(开发存储库); libs-release-local (release repository) libs-release-local(发布存储库)
  • Virtual repos: libs-snapshot (includes libs-snapshot-local, libs-release-local and remote-repos); 虚拟仓库:libs-snapshot(包括libs-snapshot-local,libs-release-local和remote-repos); libs-release (includes libs-release-local and remote repos) libs-release(包括libs-release-local和remote repos)

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: 你必须做两个步骤:

  1. mvn versions:use-releases (This will change all SNAPSHOT to release versions) mvn versions:use-releases (这会将所有SNAPSHOT更改为发布版本)
  2. 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.

相关问题 Maven插件版本:版本之后找不到软件包:use-latest-versions - Versions Maven Plugin: package not found after versions:use-latest-versions Maven 版本发布候选和快照 - maven versions release candidates and snapshot Maven版本插件更新到下一个快照 - Maven versions plugin update to next snapshot 运行Maven版本时的不同行为:use-latest-versions目标 - Different behavior when running the Maven versions:use-latest-versions goal 如何制作maven版本:use-latest-versions在dependencyManagement中逐步增加import scoped条目? - How to make maven versions:use-latest-versions step up import scoped entry in dependencyManagement? Nexus:查询快照版本的所有时间戳版本 - Nexus: query all timestamped versions of a snapshot version Maven发行插件可以检查通过Maven依赖插件下载的工件中的SNAPSHOT版本吗? - Can maven-release-plugin check for SNAPSHOT versions in artifacts downloaded via maven-dependency-plugin? Maven存储库中SNAPSHOT版本的规则 - Rules for SNAPSHOT versions in Maven repository 詹金斯将人工制品部署到Artifactory。 maven-metadata.xml显示的发行版本不正确,并且不显示快照的版本 - Jenkins deploying artifacts to Artifactory. maven-metadata.xml shows incorrect version for release and does not show versions for snapshot maven 版本插件:如何将父版本更新为特定版本,而不是最新版本? - maven versions plugin: How to update parent to specific version, not latest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM