From d59675fab74acfcb19063b7f0081cb22ef3e4d5e Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 2 Jun 2020 23:03:57 +0100 Subject: [PATCH] JAL-3225 Using Gradle Git-Version plugin to set gitHash and gitBranch Using Gradle Git-Version instead of exec to run git directly allows buildship to successfully import the project into eclipse without a command line git installed. Essential for development within Eclipse in Windows without having to install either gradle or git as command line tools. --- build.gradle | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 39c8261..a3ca4b8 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '4.0.3' id 'com.install4j.gradle' version '8.0.4' id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree + id 'com.palantir.git-version' version '0.12.3' } repositories { @@ -346,8 +347,9 @@ ext { modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"]) modules_runtimeClasspath = modules_compileClasspath */ - gitHash = string("") - gitBranch = string("") + def details = versionDetails() + gitHash = details.gitHash + gitBranch = details.branchName println("Using a ${CHANNEL} profile.") @@ -991,36 +993,10 @@ def getDate(format) { } -task setGitVals { - - doFirst { - def hashStdOut = new ByteArrayOutputStream() - def resultHash = exec { - commandLine "git", "rev-parse", "--short", "HEAD" - standardOutput = hashStdOut - ignoreExitValue true - } - - def branchStdOut = new ByteArrayOutputStream() - def resultBranch = exec { - commandLine "git", "rev-parse", "--abbrev-ref", "HEAD" - standardOutput = branchStdOut - ignoreExitValue true - } - - gitHash = resultHash.getExitValue() == 0 ? hashStdOut.toString().trim() : "NO_GIT_COMMITID_FOUND" - gitBranch = resultBranch.getExitValue() == 0 ? branchStdOut.toString().trim() : "NO_GIT_BRANCH_FOUND" - } - - outputs.upToDateWhen { false } -} - - task createBuildProperties(type: WriteProperties) { group = "build" description = "Create the ${buildProperties} file" - dependsOn setGitVals inputs.dir(sourceDir) inputs.dir(resourceDir) file(buildProperties).getParentFile().mkdirs() @@ -1688,7 +1664,6 @@ clean { task installers(type: com.install4j.gradle.Install4jTask) { group = "distribution" description = "Create the install4j installers" - dependsOn setGitVals dependsOn getdown dependsOn copyInstall4jTemplate -- 1.7.10.2