简体   繁体   English

Maven Release Plugin 和 cifriendly 版本

[英]Maven Release Plugin together with cifriendly versions

I am just setting up a Maven multi-module project with ${revision} as version as described in https://maven.apache.org/maven-ci-friendly.html我只是按照https://maven.apache.org/maven-ci-friendly.html 中的描述,使用${revision}作为版本设置 Maven 多模块项目

The property ${revision} is set in the parent POM and used as version number throughout all modules.属性${revision}在父 POM 中设置并用作所有模块的版本号。

This works fine for SNAPSHOT builds, but when I run the Maven release plugin, the version gets replaced by something like 1.0.0 and then 1.0.1-SNAPSHOT .这适用于 SNAPSHOT 构建,但是当我运行 Maven 发布插件时,版本被替换为1.0.01.0.1-SNAPSHOT类的东西。 So the cifriendly versions are gone after one release.所以cifriendly版本在发布后就消失了。

Is there a way to configure the Maven release plugin in a way that cifriendly versions are not destroyed?有没有办法以不破坏cifriendly版本的方式配置Maven发布插件?

The CI Friendly version scheme is intended to replace the Maven Release Plugin , not complement it. CI Friendly 版本方案旨在取代Maven Release Plugin而不是补充它。 In today's development world most teams are relying on CI servers for integration testing, performing automated tests and either releasing with continuous delivery or continuous deployment.在当今的开发世界中,大多数团队都依赖 CI 服务器进行集成测试、执行自动化测试以及通过持续交付或持续部署进行发布。 The concept of a SNAPSHOT is truly limited when everything is potentially a SNAPSHOT .当一切都可能是SNAPSHOT时, SNAPSHOT的概念确实受到限制。

Notably, the Release Plugin executes 4 to 5 times more processes than a properly implemented CI Friendly configuration.值得注意的是,Release Plugin 执行的进程比正确实施的 CI 友好配置多 4 到 5 倍。 Imagine a 50-minute build using the release plugin becoming a 15-minute build using the CI strategy.想象一下使用发布插件的 50 分钟构建变成使用 CI 策略的 15 分钟构建。 Now that's modernization! 现在就是现代化!

The basic idea is that values used in versions will be collected from the DVCS ( Git , SVN , etc.) and the CIS ( Jenkins , Travis CI , GitLab , etc.) at build time and used to modify or set the POM/release version.基本思想是版本中使用的值将在构建时从DVCSGitSVN等)和CISJenkinsTravis CIGitLab等)收集并用于修改或设置 POM/发布版本。 These values are things like the build number, the shortened Git hash or anything else.这些值是像内部版本号、缩短的 Git 哈希或其他任何东西。

Procedure to implement CI Friendly Maven builds:实现 CI 友好 Maven 构建的过程:

  • Maven supports only a handful of properties in the <version> tag. Maven仅支持<version>标记中的少数属性 These are ${revision} , ${changelist} and ${sha1} .它们是${revision}${changelist}${sha1}
  • You can either use a hardcoded value and the acceptable properties or just something like ${revision} .您可以使用硬编码值和可接受的属性,也可以使用${revision} NOTE: I now recommend ${revision} .注意:我现在推荐${revision}
  • In the <properties> , set values to acceptable defaults -- fake values that become clear they are from non-build machines, like 0 for the build number.<properties> ,将值设置为可接受的默认值——很明显它们来自非构建机器的假值,例如构建号为0
  • In the <properties> , assemble the value for <revision> , eg the version, from other properties and hardcoded values.<properties> ,从其他属性和硬编码值组合<revision>的值,例如版本。 For instance, <revision>1.0.0b${changelist}-${sha1}</revision> .例如, <revision>1.0.0b${changelist}-${sha1}</revision>
  • At build time, use -D flags to set the actual values.在构建时,使用-D标志设置实际值。 For instance, the ${BUILD_NUMBER} value is injected to every Jenkins build -- -Dchangelist=${BUILD_NUMBER} .例如, ${BUILD_NUMBER}值被注入到每个 Jenkins 构建中—— -Dchangelist=${BUILD_NUMBER}
  • You now have the flexibility to change the version number components.您现在可以灵活地更改版本号组件。

In the CI pipelines you can now detect the commit branch and perform releases from master by clearing all or some of these values.在 CI 管道中,您现在可以通过清除所有或部分这些值来检测提交分支并从master执行发布。 For instance, feature branches can calculate and add the Git hash.例如,功能分支可以计算并添加 Git 哈希。 The semantic version is set above -- Developers now have own and control it.语义版本在上面设置——开发人员现在拥有并控制它。 They must know their code to make changes, and they have the freedom to increment the semantic version.他们必须知道他们的代码才能进行更改,并且他们可以自由地增加语义版本。 It's a lot of valuable flexibility.这是很多宝贵的灵活性。

The sound reasoning here, though, is to speed up things and get rid of a heavyweight process that really adds little to no relevant information that ties code to its precise origin.不过,这里的合理推理是加快速度并摆脱重量级过程,该过程实际上几乎没有添加将代码与其精确来源联系起来的相关信息。 By using CI Friendly versions you will let deployers, testers and sysadmins see the compile number and code commit hash that allows the problem to be precisely correlated to an actual code release.通过使用 CI 友好版本,您将让部署人员、测试人员和系统管理员看到编译号和代码提交哈希,从而使问题与实际代码发布精确相关。

It should be noted that this requires a bit of philosophical flexibility to accept a paradigm shift.应该指出的是,这需要一点哲学上的灵活性来接受范式转变。 Change is good, and ditching the release plugin will make your release pipelines better.改变是好的,放弃发布插件会让你的发布管道更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM