1.为什么要统一管理版本?
maven父子工程多模块,每个模块还都可以独立存在,子模块往往通常希望和父工程保持一样的版本,如果每个工程单独定义版本号,后期变更打包也非常麻烦,如何维护一个全局的版本号呢?
2.如何解决呢?
bash 代码解读复制代码Maven官方文档说:自 Maven 3.5.0-beta-1 开始,可以使用 ${revision}, ${sha1} and/or ${changelist} 这样的变量作为版本占位符。
即在maven多模块项目中,可配合插件flatten-maven-plugin
及${revision}
属性来实现全局版本统一管理。
父工程
xml 代码解读复制代码"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.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-parentartifactId>
<version>2.7.18version>
parent>
<groupId>com.xxx.projectgroupId>
<artifactId>xxx-parentartifactId>
<packaging>pompackaging>
<version>${revision}version>
<modules>
<module>module1module>
<module>module2module>
<module>module3module>
modules>
<properties>
<revision>1.1.1revision>
<maven.compiler.source>8maven.compiler.source>
<maven.compiler.target>8maven.compiler.target>
properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojogroupId>
<artifactId>flatten-maven-pluginartifactId>
<version>1.3.0version>
<inherited>trueinherited>
<executions>
<execution>
<id>flattenid>
<phase>process-resourcesphase>
<goals>
<goal>flattengoal>
goals>
<configuration>
<updatePomFile>trueupdatePomFile>
<flattenMode>resolveCiFriendliesOnlyflattenMode>
<pomElements>
<parent>expandparent>
<distributionManagement>removedistributionManagement>
<repositories>removerepositories>
pomElements>
configuration>
execution>
<execution>
<id>flatten.cleanid>
<phase>cleanphase>
<goals>
<goal>cleangoal>
goals>
execution>
executions>
plugin>
plugins>
build>
project>
子模块
xml 代码解读复制代码"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-parentartifactId>
<groupId>com.xxx.projectgroupId>
<version>${revision}version>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>module3artifactId>
<properties>
<maven.compiler.source>8maven.compiler.source>
<maven.compiler.target>8maven.compiler.target>
properties>
<dependencies>
<dependency>
<groupId>com.xxx.projectgroupId>
<artifactId>module1artifactId>
<version>${revision}version>
dependency>
dependencies>
project>
编译
go 代码解读复制代码mvn clean package
基于以上操作,每次版本号变更,只需要修改父模块POM文件中的revision
即可
评论记录:
回复评论: