Skip to content

Commit 39ff04d

Browse files
committed
Merge pull request #488 from JacisNonsense/non-git-build
Enable non-git builds
2 parents 59926fa + 8846225 commit 39ff04d

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

build.gradle

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,52 @@ plugins {
1515
}
1616
apply plugin: 'nebula-aggregate-javadocs'
1717

18+
def getGitCommit = { ->
19+
String HEAD_REF = new File(rootDir, '.git/HEAD').text.replace("ref: ", "").replace("\n", "")
20+
String COMMIT_HASH = new File(rootDir, ".git/${HEAD_REF}").text.substring(0, 7)
21+
return COMMIT_HASH
22+
}
1823

1924
/*
2025
* Gets the version name from the latest Git tag
2126
* http://ryanharter.com/blog/2013/07/30/automatic-versioning-with-git-and-gradle/
2227
*/
2328
def getVersionName = { ->
24-
def stdout = new ByteArrayOutputStream()
25-
exec {
26-
commandLine 'git', 'describe', '--tags'
27-
standardOutput = stdout
29+
if (project.hasProperty("vers")) return vers
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+
if (!new File(rootDir, '.git/HEAD').exists()) {
39+
println("WARN: Could not fetch Git Tag for build version. No Git HEAD available. Substituting version 0.0.0")
40+
return "0.0.0"
41+
}
42+
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.")
43+
return getGitCommit()
2844
}
29-
return stdout.toString().trim().substring(1)
3045
}
3146

3247
def getVersionSimple = { ->
33-
def stdout = new ByteArrayOutputStream()
34-
exec {
35-
commandLine 'git', 'describe', '--tags', '--abbrev=0'
36-
standardOutput = stdout
48+
if (project.hasProperty("vers")) return vers
49+
try {
50+
def stdout = new ByteArrayOutputStream()
51+
exec {
52+
commandLine 'git', 'describe', '--tags', '--abbrev=0'
53+
standardOutput = stdout
54+
}
55+
return stdout.toString().trim().substring(1)
56+
} catch (org.gradle.process.internal.ExecException e) {
57+
if (!new File(rootDir, '.git/HEAD').exists()) {
58+
println("WARN: Could not fetch Git Tag for build version. No Git HEAD available. Substituting version 0.0.0")
59+
return "0.0.0"
60+
}
61+
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.")
62+
return getGitCommit()
3763
}
38-
return stdout.toString().trim().substring(1)
3964
}
4065

4166
allprojects {

0 commit comments

Comments
 (0)