What is JGit Flow and why do I need a Maven plugin?

If you missed my other blog post, I recently released a Java library named jgit-flow that implements the git-flow branching and merging model introduced by Vincent Driessen in Java.

My hope is that developers will use this library to integrate git-flow workflows inside of their Java apps, and to get the ball rolling, I thought I’d be the first integrator.

If you read my other blog post, you’ll remember that although git-flow is really useful, trying to make it play nice with the maven-release-plugin (MRP) leaves a lot to be desired.

In particular, some of the pitfalls of the maven-release-plugin in the context of git-flow are:

  • MRP writes .backup and release.properties files to your working tree which are easily committed when they shouldn’t be
  • MRP does a build in the prepare goal and a build in the perform goal causing tests to run 2 times
  • MRP and git-flow both create tags leaving you with two tags if you forget to delete one of them
  • If something goes wrong, MRP usually leaves you in a bad state and rollback doesn’t work most of the time

So I figured the best plan of action was to write a specific plugin to enable git-flow style release workflows, and after a bit of twiddling, I’m pleased to bring you the JGit Flow Maven Plugin.

Features

While the plugin is primarily used to perform releases, it also provides full git-flow functionality including:

  • starting a release – creates a release branch and updates pom(s) with release versions
  • finishing a release – runs a maven build (deploy or install), merges the release branch, updates pom(s) with development versions
  • starting a hotfix – creates a hotfix branch and updates pom(s) with hotfix versions
  • finishing a hotfix – runs a maven build (deploy or install), merges the hotfix branch, updates pom(s) with previous versions
  • starting a feature – creates a feature branch
  • finishing a feature – merges the feature branch

Differences with the Maven Release Plugin

Although the maven-jgitflow-plugin is based on the maven-release-plugin, it does things a bit differently to provide a cleaner workflow…

  • doesn’t create any .backup or release.properties files (or any other files in your working tree)
  • makes all changes on branches. This means to “roll-back” you can simply delete the branch
  • automatically copies any profiles (-P) and user-properties (-D) passed on the command line to the forked maven process when building
  • doesn’t run site-deploy
  • provides the ability to completely turn off maven deployment
  • provides the ability to completely turn off remote pushes/tagging
  • Only builds your project once in the finish goal. e.g. if you do release-start and release-finish together, your tests only run once
  • Never clones your project to a temp folder
  • auto tracks origin based on maven scm values if origin tracking is not already setup (I’m looking at you Bamboo!)
  • master branch is always kept at the latest release version (not a SNAPSHOT)

I’m hoping this plugin will help ease the pain of releasing maven projects with git-flow and help reduce the number of groans when someone says “can you do a maven release of…”

To get started, check out the plugin’s wiki. And when things don’t work, let me know in the plugin’s issue tracker.

If you’re interested in contributing, please fork the Maven JGitFlow Plugin on Bitbucket. When your super cool new feature is ready, just issue a pull request to the develop branch of the main project.

Enjoy!

resources

Wiki: https://bitbucket.org/atlassian/jgit-flow/wiki
Issue Tracker: https://ecosystem.atlassian.net/projects/MJF
Google Group: https://groups.google.com/forum/#!forum/maven-jgitflow-users
Source Code: https://bitbucket.org/atlassian/jgit-flow

Check out more developer resources from Atlassian:

Git Tutorials

Maven Git Flow Plugin for Better Releases