【发布时间】:2016-07-24 12:01:26
【问题描述】:
我正在使用 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 存储库用作可以具有 -SNAPSHOT 依赖版本的依赖存储库)。这些版本更新检查回源代码控制 (svn)。
当代码(包括 pom.xml 版本更新更改)从分支合并回主干并执行主干构建时,所有 com.example* 内部依赖版本都应更改/更新为最新发布版本。但是由于某些原因,当依赖版本中包含“-SNAPSHOT”时,versions:use-latest-versions 不会将版本更改/更新为最新版本(无 -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 和远程仓库)
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>
...
【问题讨论】:
标签: maven plugins release snapshot versions