Using maven release plugin

Keywords: Maven snapshot svn nexus

In order to facilitate development, we usually use SNAPSHOT version. After stage development, we need to change SNAPSHOT to release version (such as 1.0.0.SNAPSHOT - "1.0.0) to prevent online environment from being damaged. The manual step is to delete the SNAPSHOT, then tag the code (for backup), then mvn deploy uploads the release version jar package to the Maven warehouse, and finally changes the version number to 1.0.1.SNAPSHOT, which is too troublesome. Fortunately, Maven provides a maven release plugin plug-in. Let's see how to use it.

1, POM file configuration

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <!-- Branched svn address -->
            <configuration>
                <tagBase>http://ip:port/aaa/bbb/tags/</tagBase>
            </configuration>
        </plugin>
    </plugins>
</build>

<!-- maven Private service address, release Plugins will bring release Of jar Package auto upload -->
<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://ip:port/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://ip:port/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

<!-- svn I'm not sure what the three differences are. maven The version will be uploaded automatically after modification -->
<scm>
    <url>http://ip:port/aaa/bbb/trunk/</url>
    <connection>scm:svn:http://ip:port/aaa/bbb/trunk/</connection>
    <developerConnection>scm:svn:http://ip:port/aaa/bbb/trunk/</developerConnection>
</scm>

2, Execute command

#-Darguments="-DskipTests" means skipping tests
mvn release:prepare -Darguments="-DskipTests"

It will let you enter the version number and other information you need, and you can enter it by yourself according to the situation.

After execution, a branch will appear under the tags folder, and the version number of the project has been changed to the version number entered previously, and the project has been uploaded to SVN automatically.

At this time, there will be some redundant files in the project. Don't delete them first. The next command is useful.

#This command will transfer it to the project checkout of tags, compile and upload, that is, upload the jar package of release version
mvn release:perform -Darguments="-DskipTests"

#After all, execute the following command to clear the redundant files generated before
mvn release:clean

OK, then we have completed the code branch and version number modification

Posted by jbx on Thu, 02 Jan 2020 08:25:16 -0800