Monday, September 15, 2014

Releasing a Project Using Maven Release Plugin

Maven Release Plugin

  • This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. Releasing a project is made in two steps: prepare and perform.

Requriements:

1)  Current version specified in your projects pom.xml should be a SNAPSHOT version
 eg. 1.1-SNAPSHOT

2) your projects pom.xml should contain the scm connection settings specified inside scm tag (maven-scm-plugin)
eg.
<scm>
        <connection>scm:svn:https://your.projects.svn.path</connection>
        <developerConnection>scm:svn:https://
your.projects.svn.path</developerConnection>
    </scm>

"https://your.projects.svn.paththis is the path where maven checkins the next developemnt version
3) your pom.xml must contain repositories configuration under distributionManagement tag.
eg.
<distributionManagement>
          <repository>
            <id>releases</id>
            <name>Releases</name>
            <url>http://your.server.path/nexus/content/repositories/releases/</url>
            <layout>default</layout>
          </repository>
          <snapshotRepository>
            <id>snapshots</id>
            <name>Snapshots</name>
            <url>http://your.server.path/nexus/content/repositories/snapshots/</url>
            <layout>default</layout>
          </snapshotRepository>
    </distributionManagement>

4) your maven's settings.xml must contain the required server configuration
eg.

<servers>
       <server>
            <id>releases</id>
            <username>yourusername</username>
            <password>yourpassword</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>yourusername</username>
            <password>yourpassword</password>
        </server>
        </servers>

Steps to follow :

  1. mvn release:prepare -DdryRun=true -DautoVersionSubmodules=true -P "production" -DtagBase=https://your.svn.tagbase.path

    "https://your.svn.tagbase.path" this is the path where branch/tag is created for the current release, which is than checkout in target folder and the same is uploaded on nexus during perform step.
  2. mvn release:perform -DdryRun=true -P "production"
  3. mvn release:clean
  4. mvn release:prepare -DautoVersionSubmodules=true -P "production" -DtagBase=https://your.svn.tagbase.path
  5. mvn release:perform -P "production"
  6. Dependent project POM files should refer new SNAPSHOT version.
  7. If problem occurred while performing common release than execute the below commands for rollback.

    a) mvn release:rollback

    To rollback a release, the following requirement must be met:
    • You haven't run release:clean on the project. This means that the backup files and the release descriptor from the previous release command still exists.
    When a release is rolled back, the following release phases are executed:
    • All project POMs are reverted back to their pre-release state locally, and also in the SCM if the previous release command was able to successfully make changes in the SCM to the POMs. This is done by using the backup files created during release:prepare.
    Currently we have to manually delete the branch/tag from scm.

    b) mvn release:clean
    
    Cleaning a release goes through the following release phases:
    • Delete the release descriptor (release.properties)
    • Delete any backup POM files

 

Reference : http://maven.apache.org/maven-release/maven-release-plugin/index.html

No comments:

Post a Comment