From 5e6b4fe5fec1ca7d88633811027155dcba20234c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 7 Oct 2017 16:03:13 +0200 Subject: [PATCH] Include generated version information --- .gitignore | 1 + build.gradle | 2 ++ version.gradle | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 version.gradle diff --git a/.gitignore b/.gitignore index ea8c4bf..99b31c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/src/generated diff --git a/build.gradle b/build.gradle index 3d6ffe0..51398e8 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,8 @@ dependencies { testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3' } +apply from: 'version.gradle' + task fatJar(type: Jar) { archiveName = project.name + '-jar-with-dependencies.jar' from { (configurations.runtime - configurations.provided).collect { it.isDirectory() ? it : zipTree(it) } } diff --git a/version.gradle b/version.gradle new file mode 100644 index 0000000..95ae89c --- /dev/null +++ b/version.gradle @@ -0,0 +1,36 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath group: "org.ajoberstar", name: "gradle-git", version: "1.3.0" + } +} + +import org.ajoberstar.grgit.Grgit + +task(writeVersion) << { + def grgit = Grgit.open(dir: project.rootDir) + def version = grgit.resolve.toCommit("HEAD").id + def niceVersion = grgit.describe() + grgit.close() + + new File("src/generated/resources").mkdirs() + project.file("src/generated/resources/version.yaml").withWriter { out -> + out.println "id: ${version}" + out.println "nice: ${niceVersion}" + } +} + +sourceSets { + main { + resources { + srcDirs += "src/generated/resources" + } + } +} + +processResources { + dependsOn(writeVersion) +} + -- 2.7.4