maven父子工程多模塊統(tǒng)一管理版本號的解決方法
1.為什么要統(tǒng)一管理版本?
maven父子工程多模塊,每個模塊還都可以獨(dú)立存在,子模塊往往通常希望和父工程保持一樣的版本,如果每個工程單獨(dú)定義版本號,后期變更打包也非常麻煩,如何維護(hù)一個全局的版本號呢?
2.如何解決呢?
Maven官方文檔說:自 Maven 3.5.0-beta-1 開始,可以使用 ${revision}, ${sha1} and/or ${changelist} 這樣的變量作為版本占位符。
即在maven多模塊項(xiàng)目中,可配合插件flatten-maven-plugin
及${revision}
屬性來實(shí)現(xiàn)全局版本統(tǒng)一管理。
父工程
<?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.引用
https://maven.apache.org/maven-ci-friendly.html
到此這篇關(guān)于maven父子工程多模塊統(tǒng)一管理版本號的解決方法的文章就介紹到這了,更多相關(guān)maven一管理版本號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JAVA中@ApiModel和@ApiModelProperty注解實(shí)戰(zhàn)代碼
這篇文章主要給大家介紹了關(guān)于JAVA中@ApiModel和@ApiModelProperty注解的相關(guān)資料,@ApiModel注解是用在接口相關(guān)的實(shí)體類上的注解,它主要是用來對使用該注解的接口相關(guān)的實(shí)體類添加額外的描述信息,常常和@ApiModelProperty注解配合使用,需要的朋友可以參考下2024-03-03Java編寫網(wǎng)絡(luò)聊天程序?qū)嶒?yàn)
這篇文章主要為大家詳細(xì)介紹了Java編寫網(wǎng)絡(luò)聊天程序?qū)嶒?yàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08SpringBoot自定義注解使用讀寫分離Mysql數(shù)據(jù)庫的實(shí)例教程
這篇文章主要給大家介紹了關(guān)于SpringBoot自定義注解使用讀寫分離Mysql數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Mybatis-Plus最優(yōu)化持久層開發(fā)過程
Mybatis-plus(簡稱MP)是一個Mybatis的增強(qiáng)工具,在mybatis的基礎(chǔ)上只做增強(qiáng)不做改變,提高效率,自動生成單表的CRUD功能,這篇文章主要介紹了Mybatis-Plus最優(yōu)化持久層開發(fā),需要的朋友可以參考下2024-07-07java計(jì)算給定字符串中出現(xiàn)次數(shù)最多的字母和該字母出現(xiàn)次數(shù)的方法
這篇文章主要介紹了java計(jì)算給定字符串中出現(xiàn)次數(shù)最多的字母和該字母出現(xiàn)次數(shù)的方法,涉及java字符串的遍歷、轉(zhuǎn)換及運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-02-02idea自帶Jacoco/idea自動測試語句覆蓋率方法(使用詳解)
這篇文章主要介紹了idea自帶Jacoco/idea自動測試語句覆蓋率方法,本文給大家分享使用方法,通過圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04Springboot 1.5.7整合Kafka-client代碼示例
這篇文章主要介紹了Springboot 1.5.7整合Kafka-client代碼示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10springboot整合shardingsphere和seata實(shí)現(xiàn)分布式事務(wù)的實(shí)踐
本文主要介紹了springboot整合shardingsphere和seata實(shí)現(xiàn)分布式事務(wù)的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07Spring boot使用spring retry重試機(jī)制的方法示例
這篇文章主要介紹了Spring boot使用spring retry重試機(jī)制的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01