My favorites | Sign in
Project Logo
                
Search
for
Updated Jan 14, 2008 by mattijshoitink
Labels: Developer, Resource
MavenReleasePlugin  

# How to use the Maven2 release plugin

Introduction

Maven2 has a really nice plugin which is called release :) This plugin lets you release a version of your project controlled by Maven in a breeze.

Details

A Maven project consists of a pom file which defines a project. One of the aspects of a project is its version. Every release of your project changes the version in the pom file. If your project consists of several pom files it is very difficult and error prone to keep all the version numbers in sync.

This is where the maven release plugin comes in. The plugin offers you several commands to update all the versions in your pom files, update them to your svn repository and create a tag for the version. The plugin does the following steps for you:

  * Check that there are no uncommitted changes in the sources
  * Check that there are no SNAPSHOT dependencies
  * Change the version in the poms from x-SNAPSHOT to a new version (you will be prompted for the versions to use)
  * Transform the SCM information in the POM to include the final destination of the tag
  * Run the project tests against the modified POMs to confirm everything is in working order
  * Commit the modified POMs
  * Tag the code in the SCM with a version name (this will be prompted for)
  * Bump the version in the POMs to a new value y-SNAPSHOT (these values will also be prompted for)
  * Commit the modified POMs

Copied from the Maven Release Plugin Homepage1

Constraints for a release

First of all, the scm (Source controle management) type and url need to be specified in the pom.xml. For Webical this url looks like this:

...
 <!-- 
   svn connectivity
   use: mvn scm:update to update the project sources 
   use: mvn scm:checkin to commit the project sources 
 -->
 <scm>
    <connection>
        scm:svn:http://webical.googlecode.com/svn/trunk
    </connection>
 </scm>
...

The release plugin checks for a few things when you want to release a new version. It checks that there are no changes in the project you want to release. It is wise to export the project you want to release to a separate directory to be sure there are no changes. The release plugin will notify you if any changes exist and will abort the release procedure.

The release plugin also checks you don't have any dependencies with a SNAPSHOT version in your project. All dependencies in your project must be an actual release.

The release plugin starts a second instance of Maven to perform some tasks for you. It can only do this if you added Maven to your PATH. If this is not the case, the release procedure will abort with an error.

Usage

It is wise you start with a dry run. This creates the pom files as if they were going to be commited to your svn repository. To perform a dry run, enter the directory of the project you want to release and execute the following command:

 mvn release:prepare -DdryRun=true

A series of questions is presented to you on the screen including the new version number and the name of the tag. You are also asked to give the version of any sub-projects.

The command creates a release.properties file with all the values needed for the release. It also creates several pom files which you can check:

This is done for all the project and all of its sub-projects. The original pom.xml files are left intact since this is a dry run.

The actual release

If all the values in the release.properties file are correct, and all the pom files are correct you can perform the actual release. This is done with the following command:

 mvn release:prepare release:perform

This command will NOT ask you the questions again. The values you entered are stored in the release.properties file and the release plugin assumes these values are still correct. The command above will alter the pom files to the new version, create and commit a tag and commit the new pom files. All with the values you enetered in the dry run.

Start over?

If you are not satisfied with the generated pom files or the release.properties file from the dry run you can reset the release. This can be done in two ways:

 // the release:clean goal
 mvn release:clean release:perform -DdryRun=true

 // the -Dresume=false option
 mvn release:perform -Dresume=false -DdryRun=true

This will start the process again and will ask you to answer the questions again.

Refrences

  1. Maven release plugin homepage
  2. Maven homepage

Sign in to add a comment
Hosted by Google Code