maven父子工程多模塊統(tǒng)一管理版本號(hào)的解決方法
1.為什么要統(tǒng)一管理版本?
maven父子工程多模塊,每個(gè)模塊還都可以獨(dú)立存在,子模塊往往通常希望和父工程保持一樣的版本,如果每個(gè)工程單獨(dú)定義版本號(hào),后期變更打包也非常麻煩,如何維護(hù)一個(gè)全局的版本號(hào)呢?
2.如何解決呢?
Maven官方文檔說(shuō):自 Maven 3.5.0-beta-1 開(kāi)始,可以使用 ${revision}, ${sha1} and/or ${changelist} 這樣的變量作為版本占位符。
即在maven多模塊項(xiàng)目中,可配合插件flatten-maven-plugin
及${revision}
屬性來(lái)實(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
基于以上操作,每次版本號(hào)變更,只需要修改父模塊POM文件中的revision
即可
3.引用
https://maven.apache.org/maven-ci-friendly.html
到此這篇關(guān)于maven父子工程多模塊統(tǒng)一管理版本號(hào)的解決方法的文章就介紹到這了,更多相關(guān)maven一管理版本號(hào)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java優(yōu)化for循環(huán)嵌套的高效率方法
這篇文章主要介紹了Java優(yōu)化for循環(huán)嵌套的高效率方法,幫助大家更好的提升java程序性能,感興趣的朋友可以了解下2020-09-09Windows10系統(tǒng)下JDK1.8的下載安裝及環(huán)境變量配置的教程
這篇文章主要介紹了Windows10系統(tǒng)下JDK1.8的下載安裝及環(huán)境變量配置的教程,本文圖文并茂給大家介紹的非常詳細(xì),對(duì)大家的工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03Java 時(shí)間格式轉(zhuǎn)換之impleDateFormat與Data API解析與使用
想必大家對(duì) SimpleDateFormat 并不陌生。SimpleDateFormat 是 Java 中一個(gè)非常常用的類(lèi),他是以區(qū)域敏感的方式格式化和解析日期的具體類(lèi)。 它允許格式化 (date -> text)、語(yǔ)法分析 (text -> date)和標(biāo)準(zhǔn)化2021-11-11Spring與Dubbo搭建一個(gè)簡(jiǎn)單的分布式詳情
這篇文章主要介紹了Spring與Dubbo搭建一個(gè)簡(jiǎn)單的分布式詳情,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08Springboot2 session設(shè)置超時(shí)時(shí)間無(wú)效的解決
這篇文章主要介紹了Springboot2 session設(shè)置超時(shí)時(shí)間無(wú)效的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07