Project release and version management using gradle and git
Two very useful Gradle plugins:
1. axion-release-plugin https://github.com/allegro/axion-release-plugin
This plugin derives project version from tags in git repository. I use following rules in my projects:
- Start with default version 0.1.0-SNAPSHOT
- Every release of master branch increments second digit
- Production emergency fixes are done on a branch, which is created from the version tag. Such branch name must start with "hotfix-" prefix. Releasing this branch will increment 3rd digit.
- Feature branches must have "topic-" prefix. They are never released, however their version includes feature name.
To check current project version run “gradle currentVersion” To release the project run “gradle release”
2. gradle-nexus-plugin https://github.com/bmuschko/gradle-nexus-plugin
This plugin adds ability to upload project artifacts to nexus repository. Simply run “gradle upload”.
Example gradle.build
buildscript {
repositories {
maven {url = 'http://repo1.maven.org/maven2'}
}
}
plugins {
id 'java'
id 'pl.allegro.tech.build.axion-release' version '1.3.4'
id 'com.bmuschko.nexus' version '2.3.1'
}
scmVersion {
versionIncrementer 'incrementMinor'
branchVersionIncrementer = [
'hotfix-.*' : { c -> c.currentVersion.incrementPatchVersion() }
]
branchVersionCreator = [
'topic-.*' : 'versionWithBranch'
]
}
group 'com.jpragma.myproject'
version = scmVersion.version
repositories {
jcenter {url = 'http://jcenter.bintray.com/'}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
}
nexus {
sign = false
repositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal/'
snapshotRepositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal-snapshots/'
}
Written on July 12, 2016