Software Development – Java – Open Source
« Easy way to display your apps version number using Maven | Suns Troubleshooting Guide for Java »

Automatically create releases and maintenance branches with Maven

Tuesday, July 17th, 2007 at 12:43 am

First of all you need version at least 2.0-beta-6 of the Maven Release Plugin if you want the branching feature. I just deleted the <home>/.m2/repository/org/apache/maven/plugins/maven-release-plugin folder to get Maven to download the latest version. If you never used the release plugin before it will download the latest version anyway.

Now let’s say you’ve got version 1.0.0-SNAPSHOT of your artifact and you want to cut a release: the normal procedure would be to run

mvn release:prepare release:perform

To get this running you need two prerequisites in you pom.xml:

  1. a scm section
  2. a distributionManagement section

Those might look like this:

<scm>
  <connection>scm:svn:http://<yourhost>/release-test/trunk/</connection>
  <developerConnection>scm:svn:http://<yourhost>/release-test/trunk/</developerConnection>
</scm>

<distributionManagement>
  <repository>
    <id>repo</id>
    <name>Local Repo</name>
    <url>file:///c:/tmp/repo</url>
  </repository>
</distributionManagement>

From now on I assume that your project name is release-test. You also need to make sure that there is a folder http://<yourhost>/release-test/tags in your repo. Maven needs this folder to tag the released version unless you told Maven otherwise.

Assure that everything is checked in and you’ve got no changes in your checked out copy. If you now call

mvn release:prepare release:perform

and accept 1.0.1-SNAPSHOT as the next development version Maven will nicely build your application, tag the sources in svn and modify your pom.xml to reflect the next development version. This is already quite cool and saves a lot of time. But …

… I like to create maintenance branches after such a release. So I would choose 1.1.0-SNAPSHOT as the next development version and create a branch containing a 1.0.1-SNAPSHOT version derived from the 1.0.0 Release. Creating branches and modifying pom.xmls is quite tedious (unless you wrote yourself a script to do the stupid work). This is where the release plugins new branch feature comes into play.

Before I create my 1.0.0 release I create a 1.0.x branch with Maven. Just make sure you’ve got a http://<yourhost>/release-test/branches folder in your repository. Now call

mvn release:branch -DbranchName=1.0.x

Maven will ask you for the new working copy version. Enter 1.1.0-SNAPSHOT as this will be our new bleeding edge development version. Maven now creates a branch at http://<yourhost>/release-test/branches/1.0.x which contains a pom.xml with version 1.0.0-SNAPSHOT and modifies the version in your trunks pom.xml to be 1.1.0-SNAPSHOT.

To finally cut your 1.0.0 release you have to checked out your branch http://<yourhost>/release-test/branches/1.0.x and do the usual

mvn release:prepare release:perform

which will suggest the correct version numbers. Subsequent maintenance release are created of this branch in the same fashion.

This got a bit longer than I thought ;) If you’ve got any questions – ask. I’ll be more than happy to go into further detail if needed

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Automatically create releases and maintenance branches with Maven”

  1. Arul Says:
    September 8th, 2009 at 11:32 pm

    Hi,

    We are getting the following error when trying to execute release:branch

    org.apache.maven.shared.release.scm.ReleaseScmCommandException: Unable to branch SCM
    Provider message:
    The svn branch command failed.
    Command output:
    svn: Commit failed (details follow):
    svn: File ‘/java/testproject/branches/testproject-5.x/testlib/pom.xml’ already exists

    The testproject has 2 modules included in the pom.xml

  2. Chris Kiehl Says:
    September 12th, 2009 at 9:33 am

    @Arul I don’t know what the problem is, but it sounds a bit like you got hit by this bug: http://jira.codehaus.org/browse/MRELEASE-446

Leave a Reply