James Ridgway - Software Engineer

Gradle Git Flow Plugin

A gradle plugin for inferring the version from the state of the git repository where a Git Flow workflow is being used.

Usage

Apply the plugin and add it as a classpath dependency as demonstrated below:

Example build.gradle:

apply plugin: 'uk.co.jamesridgway.gradle.gitflow.plugin'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'uk.co.jamesridgway:gradle-gitflow-plugin:1.2.0'
    }
}

That's all it takes, the plugin will set the version attribute of your build automatically.

Configuration

The unreleased version format can be configured:

gitflow {
    // Customise template for unreleased version (uses freemarker)
    unreleasedVersionTemplate "${major}.${minor}.${patch}-${branch?replace('/', '_')}.${commitsSinceLastTag}+sha.${commitId?substring(0,7)}${dirty?then('.dirty','')}"
}

How does it work?

The plugin uses jgit to infer the version number from the state of the repository.

The version can be inferred without needing to add or alter any tasks in the gradle task graph.

Release Version

A tagged commit of the format major.minor.patch (on any branch) will be determined as a release version.

Unreleased Version

For any commit that is not tagged with a release version (major.minor.patch) an "unreleased" version will be inferred.

By default, an unreleased version is as follows:

0.0.1-feature/test1.1+sha.8661cfd.dirty
| | | |             |     |       |
| | | |             |     |       └ "dirty" is ppended if the commit is dirty
| | | |             |     └ Short commit id
| | | |             └ Number of commits since last tag
| | | └ Branch name
| | └ Patch version for last release version
| └ Minor version for last release version
└ Major version for last release version

If the repository has never been tagged for a release the version will default to 0.0.0