Skip to content

Latest commit

 

History

History
92 lines (76 loc) · 2.31 KB

23-父子多模块工程版本管理.md

File metadata and controls

92 lines (76 loc) · 2.31 KB

maven父子多模块版本管理

问题:maven多模块下,如果子模块很多,一个一个修改版本号很麻烦!

解决:版本一次性统一修改

tips: 建议使用法二

法一:maven插件versions-maven-plugin

父模块中引入插件

<!-- Maven多模块项目统一修改版本号 -->
<build>
    <plugins>
        <plugin>
            <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/versions-maven-plugin -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.11.0</version>
        </plugin>
    </plugins>
</build>
# 设置版本号
mvn versions:set -DnewVersion=6.6.6
# 回退版本
mvn versions:revert
# 提交版本
mvn versions:commit

法二:maven插件flatten-maven-plugin编译打包 => 自动替换${reversion}占位

pom.xml

<!-- Maven多模块项目统一修改版本号 -->
<plugin>
    <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/flatten-maven-plugin -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>flatten-maven-plugin</artifactId>
    <version>1.3.0</version>
    <configuration>
        <updatePomFile>true</updatePomFile>
        <flattenMode>resolveCiFriendliesOnly</flattenMode>
    </configuration>
    <executions>
        <execution>
            <id>flatten</id>
            <phase>process-resources</phase>
            <goals>
                <goal>flatten</goal>
            </goals>
        </execution>
        <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<properties>
    <revision>1.0.1</revision>
</properties>

pom.xml

tips: 中间不能跨级引用${revision} ex: 父工程下有子工程A,A下有B,如果A未引用${revision}则B也无法引用${revision}

<parent>
    <artifactId>service</artifactId>
    <groupId>com.zhengqing</groupId>
    <version>${revision}</version>
</parent>

工程会自动生成.flattened-pom.xml文件 里面是变量替换为具体版本的pom文件,在编译构建的时候,maven不读pom.xml而去读取.flattened-pom.xml的内容完成构建。