From: Ben Soares Date: Tue, 2 Jun 2020 22:03:57 +0000 (+0100) Subject: JAL-3225 Using Gradle Git-Version plugin to set gitHash and gitBranch X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~49 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d59675fab74acfcb19063b7f0081cb22ef3e4d5e;p=jalview.git 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. --- 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