Skip to content

Commit 78890c7

Browse files
committed
Use git describe to infer version name
1 parent 0a2beca commit 78890c7

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
allprojects {
22
group = 'com.auth0'
3-
version = '0.0.1-SNAPSHOT'
43

54
repositories {
65
jcenter()

lib/build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,55 @@ dependencies {
1414
testCompile 'com.squareup.okhttp:mockwebserver:2.5.0'
1515
testCompile 'com.jayway.awaitility:awaitility:1.6.4'
1616
}
17+
18+
def semver = defineVersion()
19+
version = semver.stringVersion
20+
21+
jar {
22+
baseName = "auth0"
23+
}
24+
25+
logger.lifecycle("Using version ${version} for ${name}")
26+
27+
def defineVersion() {
28+
def current = describeGit(false)
29+
def snapshot = current == null
30+
if (snapshot) {
31+
current = describeGit(snapshot, "0.0.1")
32+
}
33+
return new Semver(snapshot: snapshot, version: current)
34+
}
35+
36+
def describeGit(boolean snapshot, String defaultValue = null) {
37+
def arguments = ['describe', '--tags']
38+
arguments.add(snapshot ? '--abbrev=0' : '--exact-match')
39+
def stdout = new ByteArrayOutputStream()
40+
def string = defaultValue
41+
try {
42+
def result = project.exec {
43+
executable = 'git'
44+
args = arguments
45+
standardOutput = stdout
46+
}
47+
48+
result.assertNormalExitValue()
49+
50+
if (stdout.toByteArray().length > 0) {
51+
string = stdout.toString().replace("\n", "")
52+
}
53+
} catch(Exception e) {
54+
logger.debug("Failed git describe command", e)
55+
} finally {
56+
stdout.close()
57+
}
58+
return string
59+
}
60+
61+
class Semver {
62+
def version
63+
def snapshot
64+
65+
def getStringVersion() {
66+
return snapshot ? version + "-SNAPSHOT" : version
67+
}
68+
}

0 commit comments

Comments
 (0)