gpt4 book ai didi

maven - 为什么使用 Maven 版本插件(版本 :use-latest-versions) not updating/changing -SNAPSHOT version to release (none -SNAPSHOT version)?

转载 作者:行者123 更新时间:2023-12-04 17:26:36 31 4
gpt4 key购买 nike

我正在使用 Version Maven Plugin插件 use-latest-versions将 groupID=com.example* 内部依赖版本更新到最新版本的功能。这是使用 Jenkins 作为我们 CI 系统的一部分执行的。

当开发人员开始开发新功能时,他们将代码分支,在分支上工作,当新功能实现(或部分实现)时,代码会合并回主干(通常每周多次)。

分支版本更新:

  • 使用“快照”配置文件。见下文 pom.xml 快照配置文件配置和 Artifactory repo 配置
  • 用于更新版本的命令:mvn -P snapshot -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false -DallowSnapshots=true ...

  • 中继版本更新:
  • 使用“生产”配置文件。见下文 pom.xml 生产配置文件配置和 Artifactory 配置
  • 用于更新版本的命令:mvn -P production -B versions:use-latest-versions versions:update-properties -Dincludes=com.example* -DexcludeReactor=false ...

  • 有时分支构建更新 com.example* 依赖版本到“..​​.-SNAPSHOT”版本(这是正常的,因为 libs-snapshot Artifactory repo 被用作可以具有 -SNAPSHOT 依赖版本的依赖库)。这些版本更新检查回源代码控制 (svn)。

    当代码(包括 pom.xml 版本更新更改)从分支合并回主干并执行主干构建时,所有 com.example* 内部依赖版本都应更改/更新为最新发布版本。但是由于某些原因,依赖版本中有“-SNAPSHOT” 版本:使用最新版本 没有将版本更改/更新为最新版本(无 -SNAPSHOT)版本。

    示例:

    Artifactory repos 有流动的版本:
  • libs-snapshot 有“com.example:myLib:1.1.10-SNAPSHOT”、“com.example:myLib:1.1.11-SNAPSHOT”
  • libs-release 有“com.example:myLib:1.1.9”、“com.example:myLib:1.1.12”

  • 构建 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>
    ...

    将代码合并回主干,包括上述依赖版本更改并运行主干构建(包括版本更新) mvn -P production -B versions:use-latest-versions...不会将 com.example:myLib 版本更改为 1.1.12

    神器配置:
  • 本地仓库:libs-snapshot-local(开发仓库); libs-release-local(发布存储库)
  • 虚拟仓库:libs-snapshot(包括 libs-snapshot-local、libs-release-local 和 remote-repos); libs-release(包括 libs-release-local 和远程 repos)


  • 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>

    ...

    最佳答案

    您应该确保您使用的是最新版本的插件 (2.3)。我相信2.3 fixed some issues (话虽如此,它仍然是一个令人难以置信的错误插件)。

    我发现版本插件的另一个问题是与其他版本目标甚至其他 maven 目标相结合。不要那样做。例如,您上面的代码正在运行 versions:use-latest-versions versions:update-properties同时。而是执行 mvn每个目标一次。是的,这很痛苦并且会减慢构建过程,但我发现它更可靠特别是如果您使用版本:update-parent (虽然 2.3 可能已经解决了这些问题)。

    我也觉得 excludeReactor is generally broken .如果您在聚合项目上运行版本更新,我不推荐它。而是转到每个子模块并运行命令。

    关于maven - 为什么使用 Maven 版本插件(版本 :use-latest-versions) not updating/changing -SNAPSHOT version to release (none -SNAPSHOT version)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36411231/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com