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

maven父子工程多模块如何管理统一的版本号?

1.为什么要统一管理?

maven父子工程多模块,每个模块还都可以独立存在,子模块往往通常希望和父工程保持一样的版本,如果每个工程单独定义版本号,后期变更打包也非常麻烦,如何维护一个全局的版本号呢?

2.如何解决呢?

Maven官方文档说:自 Maven 3.5.0-beta-1 开始,可以使用 ${revision}, ${sha1} and/or ${changelist} 这样的变量作为版本占位符。

即在maven多模块项目中,可配合插件flatten-maven-plugin${revision}属性来实现全局版本统一管理。

父工程

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-parent</artifactId><version>2.7.18</version></parent><groupId>com.xxx.project</groupId><artifactId>xxx-parent</artifactId><packaging>pom</packaging><version>${revision}</version><modules><module>module1</module><module>module2</module><module>module3</module></modules><properties><!-- globe version,if you can update the version for all project --><revision>1.1.1</revision><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><build><plugins><!-- 添加flatten-maven-plugin插件 --><plugin><groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId><version>1.3.0</version><inherited>true</inherited><executions><execution><id>flatten</id><phase>process-resources</phase><goals><goal>flatten</goal></goals><configuration><updatePomFile>true</updatePomFile><flattenMode>resolveCiFriendliesOnly</flattenMode><pomElements><parent>expand</parent><distributionManagement>remove</distributionManagement><repositories>remove</repositories></pomElements></configuration></execution><execution><id>flatten.clean</id><phase>clean</phase><goals><goal>clean</goal></goals></execution></executions></plugin></plugins></build>
</project>

子模块

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>xxx-parent</artifactId><groupId>com.xxx.project</groupId><version>${revision}</version></parent><modelVersion>4.0.0</modelVersion><artifactId>module3</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>com.xxx.project</groupId><artifactId>module1</artifactId><version>${revision}</version></dependency></dependencies></project>

编译

mvn clean package

  基于以上操作,每次版本号变更,只需要修改父模块POM文件中的revision即可

3.引用

  • Maven – Maven CI Friendly Versions
http://www.lryc.cn/news/438050.html

相关文章:

  • JavaScript --函数的作用域(全局和局部)
  • 贪吃蛇项目实现(C语言)——附源码
  • 【C++】42道面试经典问题总结
  • php 实现JWT
  • vue table id一样的列合并
  • xshell密钥方式连接阿里云Linux
  • Wni11 下 WSL 安装 CentOS
  • ROADM(可重构光分插复用器)-介绍
  • HarmonyOS开发之路由跳转
  • 怎么使用ai 免费生成ppt?这4个工具可以帮忙
  • Android主副屏显示-Android13
  • 什么是 SMB 服务器以及它如何工作?
  • 【python计算机视觉编程——10.OpenCV】
  • 医学数据分析实训 项目二 数据预处理预备知识(数据标准化处理,数据离差标准化处理,数据二值化处理,独热编码处理,数据PCA降维处理)
  • MySQL查询执行(四):查一行也很慢
  • 【Obsidian】当笔记接入AI,Copilot插件推荐
  • Spring Cloud集成Gateaway
  • 如何准备技术面试?
  • Kafka原理剖析之「Topic创建」
  • Java 高级学习路线概要~
  • 浏览器插件快速开启/关闭IDM接管下载
  • 初识c++:入门基础
  • Java Exception 异常相关总结
  • HighCharts图表自动化简介
  • 使用LDAP登录GitLab
  • 【2024】前端学习笔记5-表单标签使用
  • 数据结构--二叉树(C语言实现,超详细!!!)
  • 【将字符串变为空的编辑距离】
  • 卡特兰数的推理
  • 高精度治具加工的重要性和优势