Create file with version information on build
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 7 May 2015 05:01:30 +0000 (07:01 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 7 May 2015 05:16:13 +0000 (07:16 +0200)
.gitignore
build.gradle

index 85bd499..814a631 100644 (file)
@@ -7,3 +7,6 @@ out/
 
 /chains/
 /states/
+
+# generated directories
+src/generated/
index 9057834..643c22d 100644 (file)
@@ -14,6 +14,15 @@ version = "0.1"
 sourceCompatibility = 1.8
 targetCompatibility = 1.8
 
+buildscript {
+    repositories {
+        mavenCentral()
+    }
+    dependencies {
+        classpath group: "org.ajoberstar", name: "gradle-git", version: "1.1.0"
+    }
+}
+
 repositories {
        mavenCentral()
 }
@@ -46,4 +55,24 @@ task fatJar(type: Jar) {
        dependsOn test
 }
 
+task createVersion() {
+    sourceSets {
+        generated {
+            resources {
+                srcDir "src/generated/resources"
+            }
+        }
+    }
+    processResources.dependsOn(createVersion)
+}
+
+
+import org.ajoberstar.grgit.Grgit
+createVersion << {
+    def gitRepo = Grgit.open(".")
+    version = gitRepo.describe()
+    new File("src/generated/resources").mkdirs()
+    new File("src/generated/resources/version.txt").withWriter() { it.write(version) }
+}
+
 /* vim: set ts=4 sw=4 et: */