Automatically assign version number with Gradle ~ Collaboration with git-describe grgit-gradle BuildConfig Gradle-plugin for Java and Groovy projects
build.gradle
plugins {
id 'idea'
id 'application'
id 'org.ajoberstar.grgit' version '3.1.1'
id 'de.fuerstenau.buildconfig' version '1.1.8'
}
group 'com.example'
version = {
def tags = grgit.tag.list().collect { it.getName() }
def versionStr
if (tags.any { it ==~ /v\d.*/ }) {
versionStr = grgit.describe(longDescr: false, tags: true, match: ["v[0-9]*"])
} else {
versionStr = grgit.head().abbreviatedId
}
return versionStr + (grgit.status().isClean() ? "" : "+dirty")
}()
repositories {
mavenCentral()
}
task showVersion {
doLast {
println version
}
}
mainClassName = 'Main'
Main.java
import com.example.BuildConfig;
public class Main {
public static void main(String... args) {
System.out.println(BuildConfig.VERSION);
}
}
2f9b747 //Commit hash
v0.1
v0.0-10-g3636be7
v0.0-10-g3636be7+dirty
Recommended Posts