Maven Git Release

posted by Roberto Cortez on
tags: ,

I need to start this post by stating that I’ve only started to work seriously with Git within the last year. Unfortunately, a lot of the projects that I work on are still using SVN or CVS, but I’m now finally starting in a few that use Git.

During the last few years, I’ve done a lot of software releases using Maven Release Plugin. I still remember that I’ve took a full week just to setup the plugin in one of my projects. It worked well most of the times, but if something went wrong you could spend the next few hours fixing the problem. Oh boy, what a nightmare!

Recently, I wanted to do the same operation with a Git project and I came across with the Maven JGit-Flow Plugin and I have to tell you that this is fantastic! Very easy to setup and worked flawlessly on the first try!

This plugin is based on the development model described in the post A successful Git branching model by Vincent Driessen. Take your time to read it, since it’s very interesting.

I’m going to show you how to perform a release using this plugin. I’ll use the project from my latest post about Spring Batch as Wildfly Module.

Setup

Setup is very easy, just add the following to your pom.xml:

I’ve just added the noDeploy configuration, because I’m not releasing to a Maven repository. That’s it!

Release

Let’s look at my project branches and version:

Now, just run mvn jgitflow:release-start:

You get an interactive menu to pick the version numbers you want to release, the same way as Maven Release Plugin. I’m developing on the master branch, but during this process a release branch is created with the release versions and development branch with the new development versions.

Now the cool thing about this, is that everything is still in your local environment! If you are not happy with the changes, you can get rid of the branches and start over. No build was performed at this point.

If we want to release, just run mvn jgitflow:release-finish:

In this step, the release branch is going to get merged as described in A successful Git branching model and create the tag. Remember, nothing has been pushed yet, so you can always revert the process.

Let’s have a look into the branches and tags now:

Now you’re a push away to complete your release and ready to keep developing in your new updated development branch. How easy was that?

Conclusion

Looking into some differences between the original release plugin and jgitflow:

  • You don’t have to worry about stage commits. Everything is local until you push.
  • No more problems with other people changing pom.xml during the process.
  • Your project is only built once, saving release time.
  • Very easy to setup. Everything is picked from your Git configuration.

When I was investigating / writing, I’ve found this very interesting post, about an alternative way to perform the release. It’s worth reading: http://axelfontaine.com/blog/final-nail.html by Axel Fontaine

Comments ( 10 )

  1. ReplyPH

    Your post is awesome!

    I took the idea and made ​​a similar post in Brazilian Portuguese!

    If you find it nice gives a comment there!

    http://sitedo.ph/como-gerenciar-e-fazendo-releases-seu-projeto-com-o-git-flow-e-o-maven/

    • ReplyRoberto Cortez

      Hi PH,

      Thank you for your feedback! I’m glad the post could help you.

  2. ReplyPankaj

    Hi,

    Nice Post!!

    Quick question,

    jgitflow:release-start Creates a release branch and then update pom versions.
    Is possible to skip creating release branch ?

    Want to release my project without creating release branch.

    Thanks,

    Pankaj

    • ReplyRoberto Cortez

      Hi Pankaj,

      Thank you for the feedback.

      I’m not sure if that’s possible. It kinda defeats the all git-flow concept, but maybe you can do it by playing with flowInitContext configuration and pointing developmentBranchName to the master branch.

      Check the documentation here:
      http://jgitflow.bitbucket.org/release-start-mojo.html

      Cheers,
      Roberto

  3. ReplyNono Junang

    Awesome. very easy to perform release. Thanks for the great post.

    • ReplyRoberto Cortez

      Hi Nono,

      Thank you very much for the feedback!

      Cheers,
      Roberto

  4. Replyxiaoyuzhzh

    This is impressive , but when I try to use this plugin, there a block error.

    download this:

    http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/28/maven-plugins-28.pom

    always failed.

    Did that means this plugin doesn’t work any more?

    • ReplyRoberto Cortez

      Hi xiaoyuzhzh,

      Sorry for the late reply.

      The plugin works. I’ve used it today. It seems that your issue might be related with something else. Do you have a stacktrace? I’m able to see and download that file. Maybe you are behind a proxy or firewall that is blocking you?

      Cheers,
      Roberto

  5. ReplyMcFoggy

    by using jgitver-maven-plugin you could also not pollute your git history with fake commits to update the poms version (exactly like maven-release-plugin also does 🙁 ).
    Using it a releases could imply be realized using: git tag -a X.Y.Z && mvn deploy

    • ReplyRoberto Cortez

      Hi McFoggy,

      Sorry for this late reply.

      Thank you very much for your link. I’ll have a look.

      I agree that the commits might be annoying. I guess you could squash them together before pushing to master 🙂

      Cheers,
      Roberto

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>