Include generated version information
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 7 Oct 2017 14:03:13 +0000 (16:03 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 7 Oct 2017 14:03:13 +0000 (16:03 +0200)
.gitignore
build.gradle
version.gradle [new file with mode: 0644]

index ea8c4bf..99b31c6 100644 (file)
@@ -1 +1,2 @@
 /target
+/src/generated
index 3d6ffe0..51398e8 100644 (file)
@@ -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 (file)
index 0000000..95ae89c
--- /dev/null
@@ -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)
+}
+