当前位置: 首页 > news >正文

Maven持续集成(Continuous integration,简称CI)版本友好管理

从Maven 3.5.0-beta-1 版本开始可以在pom文件中使用 r e v i s i o n 、 {revision}、 revision{sha1}、${changelist}做为版本的占位符。

一、单module简单使用${revision}的场景
<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache</groupId><artifactId>apache</artifactId><version>18</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version>...
</project>

上述项目可以使用如下指令构建项目:

mvn -Drevision=1.0.0-SNAPSHOT clean package

随着项目的复杂度增加,上面的方案将会变的很麻烦,因此另外一种解决方案是简单地在pom文件中使用一个属性,如下所示:

<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache</groupId><artifactId>apache</artifactId><version>18</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version>...<properties><revision>1.0.0-SNAPSHOT</revision></properties>
</project>

现在就可以简单的使用mvn clean package指令对项目进行打包。当然你也可以使用如下指令更改版本:

mvn -Drevision=2.0.0-SNAPSHOT clean package

如果希望对版本进行更复杂精细的控制,可以使用 r e v i s i o n 、 {revision}、 revision{sha1}、${changelist},如下示例:

<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache</groupId><artifactId>apache</artifactId><version>18</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}${sha1}${changelist}</version>...<properties><revision>1.3.1</revision><changelist>-SNAPSHOT</changelist><sha1/></properties>
</project>

如果你想定义2.0.0-SNAPSHOT版本,只需要使用如下命令即可实现:

mvn -Drevision=2.0.0 clean package

如果想定义1.3.1版本,可以通过如下命令实现:

mvn -Dchangelist= clean package

或者想发布另一个版本2.7.8:

mvn -Drevision=2.7.8 -Dchangelist= clean package
二、多个module设置

父模块module pom定义如下:

<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache</groupId><artifactId>apache</artifactId><version>18</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version>...<properties><revision>1.0.0-SNAPSHOT</revision></properties><modules><module>child1</module>..</modules>
</project>

子模块如下:

<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><version>${revision}</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-child</artifactId>...<dependencies><dependency><groupId>org.apache.maven.ci</groupId><artifactId>child2</artifactId><version>${project.version}</version></dependency></dependencies>
</project>

这个时候如果尝试使用 r e v i s i o n 替换 {revision}替换 revision替换{project.version}将会失败。

如果想使用上述设置部署或安装项目,必须使用flatten-maven-plugin 插件,如下:

<project><modelVersion>4.0.0</modelVersion><parent><groupId>org.apache</groupId><artifactId>apache</artifactId><version>18</version></parent><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version>...<properties><revision>1.0.0-SNAPSHOT</revision></properties><build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId><version>1.1.0</version><configuration><updatePomFile>true</updatePomFile><flattenMode>resolveCiFriendliesOnly</flattenMode></configuration><executions><execution><id>flatten</id><phase>process-resources</phase><goals><goal>flatten</goal></goals></execution><execution><id>flatten.clean</id><phase>clean</phase><goals><goal>clean</goal></goals></execution></executions></plugin></plugins></build><modules><module>child1</module>..</modules>
</project>

参考文档:https://maven.apache.org/maven-ci-friendly.html
开源SDK:https://github.com/mingyang66/spring-parent


http://www.mrgr.cn/news/19012.html

相关文章:

  • 9.3C++
  • 【深入了解常用类】
  • Java笔试面试题AI答之正则表达式(2)
  • 【iOS】暑期学习总结
  • Spring 学习笔记
  • 探索 Nuxt Devtools:功能全面指南
  • Vue3 中的响应式系统:深入理解 Proxy API
  • LeetCode LCR088.使用最小花费爬楼梯
  • wget下载速度受到哪些因素影响?
  • 揭秘Java后端框架:从Spring到Netty,全方位解析!
  • 【归并分而治之】逆序对的应对之策
  • KTH5641 系列具有模拟输出的比例式线性霍尔效应传感器
  • 【Qt】消息对话框 QMessageBox
  • 7.Lab Six —— Cow Fork
  • 6. MyBatis中的@Mapper注解和XML映射文件的区别是什么?
  • 【重构获得模式 Refactoring to Patterns】
  • 屏幕像素初步认识
  • 【非常简单】 猿人学web第一届 第17题 天杀的 Http2.0
  • 最新2024年国际EI会议集合
  • C语言从头学55——学习头文件errno.h、float.h