Maven dynamically and uniformly modifies the version number

foreword

After the project is launched in 1.0 RELEASE, version update management is required. The requirements are: when the project is automatically built, the version number of the project will be changed uniformly, that is, the version number management of the maven project packaging. Let me explain in detail the several ways I collect them, I hope it will be helpful to brothers! ! !

project level

Method One

Note: The custom parameter variable env.project.version, env can be the production environment prod, the development environment dev, and the test environment test according to the project time

1. Set variables in the parent pom.xml of the maven project. as follows:

 <modelVersion>4.0.0</modelVersion>

    <groupId>com.bilibili</groupId>
    <artifactId>moba-explorer</artifactId>
    <packaging>pom</packaging>
    <version>${env.project.version}</version>

    <modules>
        <module>moba-explorer-api</module>
        <module>moba-explorer-service</module>
        <module>moba-explorer-core</module>
        <module>moba-explorer-db</module>
    </modules>

    <properties>
        <env.project.version>1.0-SNAPSHOT</env.project.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

2. Modify its submodule pom.xml

    <parent>
        <artifactId>moba-explorer</artifactId>
        <groupId>com.bilibili</groupId>
        <version>${env.project.version}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>moba-explorer-api</artifactId>
    <parent>
        <artifactId>moba-explorer</artifactId>
        <groupId>com.bilibili</groupId>
        <version>${env.project.version}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>moba-explorer-service</artifactId>
    <parent>
        <artifactId>moba-explorer</artifactId>
        <groupId>com.bilibili</groupId>
        <version>${env.project.version}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>moba-explorer-core</artifactId>
    <parent>
        <artifactId>moba-explorer</artifactId>
        <groupId>com.bilibili</groupId>
        <version>${env.project.version}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>moba-explorer-db</artifactId>

3. Use the mvn clean package plugin, or command mvn clean package

 

 4. The idea submodule uses the parent module variable to mark red: Properties in parent definition are prohibited

 

 solve:

Open the idea, search for prohibited in the setting, and remove the check box of usage of  properties  in modules parent definition is prohibited

Method Two

Note: Maven Project Version plugin

In the development of Maven projects, we often need to create SNAPSHOT packages so that other projects can use the latest code for joint debugging in real time. When packaging, we first need to change the version number version in the parent pom, and then change the version number of the parent dependency in the pom of each module in the project. If many song modules are involved, manual changes are inefficient. The IDEA plugin can help us!

After the installation is complete, there is an upward arrow sign on the Maven interface

 Click the up arrow as shown in the figure, and fill in the version number generated by hope in the pop-up box

 

 Then click Submit, and you will find that the corresponding parts of the pom files of all modules have been modified! ! !

Method Three

Note: I will update it when I have time~

Guess you like

Origin blog.csdn.net/m0_60252632/article/details/125570381