A Gradle plugin for automatically generating versions from git tags and commits.
- Add the plugin to your
build.gradle
file as shown here. - Tag your repository (anywhere in history) with a tag named like
v1.2
. - Remove the
version
property from yourbuild.gradle
file. - (Optional) Use
gradle version
or./gradlew version
to see the currentversion
.
If you want more control over how you version, you can directly access the VersionInfo
object inside your gradle script.
def versionInfo = ZoltuGitVersioning.versionInfo
print "${versionInfo.major}.${versionInfo.minor}.${versionInfo.commitCount}"
Additionally, you may also change how the plugin processes version information by specifying custom processors.
The plugin no longer supports semantic versioning out-of-box. Instead, you may specify a custom provider function which accepts the result of git describe
and returns a map of each versioning component like so:
ZoltuGitVersioning {
customDescribeProcessor { describeResults ->
def matcher = (describeResults =~ /(?<major>[0-9]+?)\.(?<minor>[0-9]+?)(?:\-(?<tags>[0-9A-Za-z\.\-]+))?\-(?<commitCount>[0-9]+?)\-g(?<sha>[a-zA-Z0-9]+)/)
matcher.matches()
[
major: matcher.group('major'),
minor: matcher.group('minor'),
commitCount: matcher.group('commitCount'),
sha: matcher.group('sha'),
tags: matcher.group('tags')
]
}
}
The default implementation merely assigns the value of VersionInfo.toString()
as the project version. If you want to perform your own processing on the version information produced by the plugin, you may do so as follows:
// With input tag '1.0.0-36'
ZoltuGitVersioning {
customVersionToString { versionInfo ->
"${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}.${versionInfo.commitCount}"
}
}
Will produce: '1.0.0.36'.
Please keep in mind that any calls to ZoltuGitVersioning.versionInfo
must occur only after declaring any custom processors.