Skip to content

Commit 21a3fd1

Browse files
committed
Add AutoVersioning to gradle
Closes #414
1 parent 201dcbb commit 21a3fd1

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

build.gradle

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

18+
19+
/*
20+
* Gets the version name from the latest Git tag
21+
* http://ryanharter.com/blog/2013/07/30/automatic-versioning-with-git-and-gradle/
22+
*/
23+
def getVersionName = { ->
24+
def stdout = new ByteArrayOutputStream()
25+
exec {
26+
commandLine 'git', 'describe', '--tags'
27+
standardOutput = stdout
28+
}
29+
return stdout.toString().trim().substring(1)
30+
}
31+
32+
def getVersionSimple = { ->
33+
def stdout = new ByteArrayOutputStream()
34+
exec {
35+
commandLine 'git', 'describe', '--tags', '--abbrev=0'
36+
standardOutput = stdout
37+
}
38+
return stdout.toString().trim().substring(1)
39+
}
40+
1841
allprojects {
1942
apply plugin: 'java'
2043
apply plugin: 'application'
@@ -36,7 +59,7 @@ allprojects {
3659
testCompile group: 'junit', name: 'junit', version: '4.12'
3760
}
3861

39-
version = '1.1.1'
62+
version = getVersionName()
4063

4164
compileJava {
4265
options.compilerArgs << "-g"
@@ -227,6 +250,7 @@ project(":ui") {
227250
appID = 'GRIP'
228251
appName = 'GRIP'
229252
mainClass = "edu.wpi.grip.ui.Main"
253+
version = getVersionSimple()
230254

231255
// This prevents the JIT from eating stack traces that get thrown a lot
232256
// This is slower but means we actually get the stack traces instead of
@@ -240,9 +264,9 @@ project(":ui") {
240264
// The JavaFX plugin does not provide a way to change the installer artifact's name without changing the appName or appID,
241265
// so instead, we simply rename the artifact to append the architecture (x86 or x64)
242266
jfxDeploy.doLast {
243-
def filet = fileTree(dir: 'build/distributions', include: "${javafx.appName}-${version}.*")
267+
def filet = fileTree(dir: 'build/distributions', include: "${javafx.appName}-${getVersionSimple()}.*")
244268
filet.each { File f ->
245-
def f2 = new File(f.getParentFile(), "${f.getName().replace("${version}", "${version}-${arch}")}")
269+
def f2 = new File(f.getParentFile(), "${f.getName().replace("${getVersionSimple()}", "${getVersionSimple()}-${arch}")}")
246270
f.renameTo(f2)
247271
}
248272
}

0 commit comments

Comments
 (0)