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.引用
https://maven.apache.org/maven-ci-friendly.html
到此这篇关于maven父子工程多模块统一管理版本号的解决方法的文章就介绍到这了,更多相关maven一管理版本号内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
解决@PostConstruct注解导致的程序无法启动(@PostConstruct的执行)
这篇文章主要介绍了解决@PostConstruct注解导致的程序无法启动(@PostConstruct的执行)问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-01-01
Java实现stream的三个常用方式(toMap,groupingBy,findFirst)
本文主要介绍了Java实现stream的三个常用方式,主要包括toMap,groupingBy,findFirst,具有一定的参考价值,感兴趣的可以了解一下2023-10-10
Redisson分布式信号量RSemaphore的使用超详细讲解
这篇文章主要介绍了Redisson分布式信号量RSemaphore的使用,基于Redis的Redisson的分布式信号量RSemaphore采用了与java.util.concurrent.Semaphore相似的接口和用法2023-02-02


最新评论