public

Gradle Project Versioning Plugin

Version management with gradle can sound like a daunting task. To solve this problem I’ve created the versionest gradle plugin to help aid you in your quest with semantic versioning automation!

Latest Post Speed kills software engineering. by Matthew Davis public

Version management with gradle can sound like a daunting task. There are a plethora of “plugins” out there that attempt to solve this problem but most of them are either disappointing, do not work or have been abandoned.

To solve this problem I’ve created the versionest gradle plugin to help aid you in your quest with semantic versioning automation!

Configuration

Getting setup to use the versionest plugin is as simple as adding a few lines to your build.gradle file and creating an initial version.properties file.

/build.gradle

Add the following (or append) to the top of your build.gradle file in your project root. This will configure the repository to look for the versionest plugin and then apply it (activate it).

buildscript {

    repositories {

        maven {

            url 'https://nexus.matthewdavis.io/repository/gradle.plugins'

        }

    }

    dependencies {

        classpath group: 'gradle.plugins', name: 'versionest', version: '0.0.30'

    }

}

apply plugin: 'versionest'
version = versionest.version.toString()
build.gradle

Notice this last line, this is where the magic happens.. each time your build runs the version variable is set by the versionest.version.toString() method which simply reads from the version.properties file.

/version.properties

This file holds the semantic version for your project. This format uses MAJOR.MINOR.PATCH:

0.1.2
version.properties

Usage

Now that our build is setup to use the plugin we can go ahead and call our gradle tasks to effectively manage the versions.

The following tasks are currently available:

bumpMajorVersion
bumpMinorVersion
bumpPatchVersion
createVersionFile
getCurrentVersion
$ gradle tasks

bumpMajorVersion bumpMinorVersion bumpPatchVersion createVersionFile getCurrentVersion

By calling a bump* task you will increment the value in version.properties auto-magically. You could then daisy chain tasks to do things like always bump on build, upload, etc.

See also

versionest is an open-source project. Source code is hosted at https://github.com/mateothegreat/gradle-plugin-versionest and jars are available via my nexus repository server at https://nexus.matthewdavis.io/#browse/browse:gradle.plugins.

Matthew Davis

Published 4 years ago