基于flatten-maven-plugin插件实现maven多模块版本管理,维护为相同版本号

pom文件引入flatten-maven-plugin插件

<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>

在父模块parent种设置版本号,使用占位符${revision}引用版本号

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxx</groupId>
    <artifactId>xxx-parent</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <revision>1.0.1.RELEASE</revision>
    </properties>

子模块中同样使用占位符引用版本号,根据模块层级调整relativePath路径

  <modelVersion>4.0.0</modelVersion>
  <parent>
	<groupId>com.xxx</groupId>
	<artifactId>xxx-parent</artifactId>
	<version>${revision}</version>
	<relativePath>../pom.xml</relativePath>
  </parent>
  <artifactId>hit-portal-gateway</artifactId>
  <packaging>jar</packaging>
  <name>hit-portal-gateway</name>

参考文章
https://www.cnblogs.com/cjsblog/p/17879729.html

posted @ 2024-09-03 20:34  S_A_W  阅读(638)  评论(0)    收藏  举报