diff options
Diffstat (limited to 'build.gradle')
-rw-r--r-- | build.gradle | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/build.gradle b/build.gradle index d159a01..70635ea 100644 --- a/build.gradle +++ b/build.gradle @@ -195,14 +195,30 @@ artifacts { archives(sourcesJar) } -sourceSets.main.getJava().srcDir(getTasks().register("generateTemplates", Copy) { task -> - task.getInputs().properties("version": getVersion()) - - task.from(file("src/main/templates")) - .into(getLayout().getBuildDirectory().dir("generated/sources/templates")) - .expand("version": getVersion()) -}.map { - it.getOutputs() -}) +sourceSets.main.getJava().srcDir( + getTasks().register("generateTemplates", Copy) { + task -> { + String version = getVersion().contains("-") ? "${getVersion()} (git-${getCurrentShortRevision()})" : getVersion() + task.getInputs().properties("version": version) + task.from(file("src/main/templates")).into(getLayout().getBuildDirectory().dir("generated/sources/templates")) + task.expand("version": version) + } + }.map { + it.getOutputs() + } +) assemble.dependsOn(shadowJar) + +String getCurrentShortRevision() { + OutputStream outputStream = new ByteArrayOutputStream() + exec { + if (System.getProperty("os.name").toLowerCase().contains("win")) { + commandLine("cmd", "/c", "git rev-parse --short HEAD") + } else { + commandLine("bash", "-c", "git rev-parse --short HEAD") + } + + setStandardOutput(outputStream) + } +}
\ No newline at end of file |