A Gradle plugin that sets various properties available for use as the version based on the git repository.
After applying the plugin, it will expose 5 properties based on the git repository:
gitVersion
The current version based on the most recent tag on the current git branch. Examples:HEAD
is tagged asv1.0.0
and thegit status
is clean, the value would bev1.0.0
.HEAD
is tagged asv1.0.0
and thegit status
is not clean, the value would bev1.0.0-1-SNAPSHOT
.HEAD^
is tagged asv1.0.0
, thegit status
is clean, and commit hash ofHEAD
is1a4440f73d7c91b53dacc072e1eab03516477c94
the value would bev1.0.0-1-g1a4440f7
.HEAD^
is tagged asv1.0.0
, thegit status
is not clean, and commit hash ofHEAD
is1a4440f73d7c91b53dacc072e1eab03516477c94
the value would bev1.0.0-2-SNAPSHOT
.
gitCommitCount
The number of commits on the current git branch.gitTagCount
The number of tags on the current git branch.gitCommitAndTagCount
The number of commits and tags on the current git branch.gitBranchName
The current git branch.
plugins {
id "com.moonlitdoor.git-version" version "0.0.7"
}
task demo {
doLast {
println "gitVersion='$gitVersion'"
println "gitCommitCount='$gitCommitCount'"
println "gitTagCount='$gitTagCount'"
println "gitCommitAndTagCount='$gitCommitAndTagCount'"
println "gitBranchName='$gitBranchName'"
}
}
$ gradlew -b build.groovy.gradle demo
> Task :demo
gitVersion='0.0.5-5-SNAPSHOT'
gitCommitCount='17'
gitTagCount='5'
gitCommitAndTagCount='22'
gitBranchName='master-1-SNAPSHOT'
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
plugins {
id("com.moonlitdoor.git-version") version "0.0.7"
}
tasks.register("demo") {
doLast {
println("gitVersion='$gitVersion'")
println("gitCommitCount='$gitCommitCount'")
println("gitTagCount='$gitTagCount'")
println("gitCommitAndTagCount='$gitCommitAndTagCount'")
println("gitBranchName='$gitBranchName'")
}
}
$ gradlew -b build.kotlin.gradle.kts demo
> Task :demo
gitVersion='0.0.5-5-SNAPSHOT'
gitCommitCount='17'
gitTagCount='5'
gitCommitAndTagCount='22'
gitBranchName='master-1-SNAPSHOT'
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.moonlitdoor:mld-git-version:master-SNAPSHOT'
}
Want to file a bug? Want to suggest an idea? Add an issue.
All Moonlit Door Software is licensed under the MIT License.
Please see CONTRIBUTING.md for details of how to build and contribute to the project.