Skip to content

Commit fc7afcd

Browse files
committed
Allow for builds to successfully compile without having Git in the path
1 parent 21c6dc8 commit fc7afcd

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

build.gradle

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,42 @@ plugins {
1616
apply plugin: 'nebula-aggregate-javadocs'
1717

1818

19+
def getGitCommit = { ->
20+
String HEAD_REF = new File(rootDir, '.git/HEAD').text.replace("ref: ", "").replace("\n", "")
21+
String COMMIT_HASH = new File(rootDir, ".git/${HEAD_REF}").text.substring(0, 7)
22+
return COMMIT_HASH
23+
}
24+
1925
/*
2026
* Gets the version name from the latest Git tag
2127
* http://ryanharter.com/blog/2013/07/30/automatic-versioning-with-git-and-gradle/
2228
*/
2329
def getVersionName = { ->
24-
def stdout = new ByteArrayOutputStream()
25-
exec {
26-
commandLine 'git', 'describe', '--tags'
27-
standardOutput = stdout
30+
try {
31+
def stdout = new ByteArrayOutputStream()
32+
exec {
33+
commandLine 'git', 'describe', '--tags'
34+
standardOutput = stdout
35+
}
36+
return stdout.toString().trim().substring(1)
37+
} catch (org.gradle.process.internal.ExecException e) {
38+
println("WARN: Could not fetch Git Tag for build version. Please install Git and add it to your PATH. For now, the Git commit hash has been substituted.")
39+
return getGitCommit()
2840
}
29-
return stdout.toString().trim().substring(1)
3041
}
3142

3243
def getVersionSimple = { ->
33-
def stdout = new ByteArrayOutputStream()
34-
exec {
35-
commandLine 'git', 'describe', '--tags', '--abbrev=0'
36-
standardOutput = stdout
44+
try {
45+
def stdout = new ByteArrayOutputStream()
46+
exec {
47+
commandLine 'git', 'describe', '--tags', '--abbrev=0'
48+
standardOutput = stdout
49+
}
50+
return stdout.toString().trim().substring(1)
51+
} catch (org.gradle.process.internal.ExecException e) {
52+
println("WARN: Could not fetch Git Tag for build version. Please install Git and add it to your PATH. For now, the Git commit hash has been substituted.")
53+
return getGitCommit()
3754
}
38-
return stdout.toString().trim().substring(1)
3955
}
4056

4157
allprojects {

0 commit comments

Comments
 (0)