maven父子工程多模塊統(tǒng)一管理版本號的解決方法
1.為什么要統(tǒng)一管理版本?
maven父子工程多模塊,每個模塊還都可以獨立存在,子模塊往往通常希望和父工程保持一樣的版本,如果每個工程單獨定義版本號,后期變更打包也非常麻煩,如何維護(hù)一個全局的版本號呢?
2.如何解決呢?
Maven官方文檔說:自 Maven 3.5.0-beta-1 開始,可以使用 ${revision}, ${sha1} and/or ${changelist} 這樣的變量作為版本占位符。
即在maven多模塊項目中,可配合插件flatten-maven-plugin
及${revision}
屬性來實現(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注解實戰(zhàn)代碼
這篇文章主要給大家介紹了關(guān)于JAVA中@ApiModel和@ApiModelProperty注解的相關(guān)資料,@ApiModel注解是用在接口相關(guān)的實體類上的注解,它主要是用來對使用該注解的接口相關(guān)的實體類添加額外的描述信息,常常和@ApiModelProperty注解配合使用,需要的朋友可以參考下2024-03-03

SpringBoot自定義注解使用讀寫分離Mysql數(shù)據(jù)庫的實例教程

Mybatis-Plus最優(yōu)化持久層開發(fā)過程

java計算給定字符串中出現(xiàn)次數(shù)最多的字母和該字母出現(xiàn)次數(shù)的方法

idea自帶Jacoco/idea自動測試語句覆蓋率方法(使用詳解)

Springboot 1.5.7整合Kafka-client代碼示例

springboot整合shardingsphere和seata實現(xiàn)分布式事務(wù)的實踐

Spring boot使用spring retry重試機(jī)制的方法示例