This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
version.gradle
69 lines (63 loc) · 2.31 KB
/
version.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def props = new Properties()
def propsFile = file("version.properties")
propsFile.withInputStream { stream ->
props.load(stream)
int versionCode = props['versionCode'].toInteger()
project.ext.set('versionCode', versionCode)
project.ext.set('versionName', getVersionName(props))
}
task incrementVersionCode {
description "Incremement the version code by one"
doLast {
def versionCode = ++props['versionCode']
props['versionCode'] = String.valueOf(versionCode)
props.store(propsFile.newWriter(), null)
project.ext.set('versionCode', versionCode)
print "Increased version code to ${project.versionCode}"
}
}
task incrementMajorVersion {
description "Increment major version"
doLast {
props['major'] = String.valueOf(++props['major'])
props['minor'] = '0'
props['hotfix'] = '0'
props.store(propsFile.newWriter(), null)
project.ext.set('versionName', getVersionName(props))
print "Increased major version to ${project.versionName}"
}
}
task incrementMinorVersion {
description "Increment minor version"
doLast {
props['minor'] = String.valueOf(++props['minor'])
props['hotfix'] = '0'
props.store(propsFile.newWriter(), null)
project.ext.set('versionName', getVersionName(props))
print "Increased minor version to ${project.versionName}"
}
}
task incrementHotfixVersion {
description "Increment hotfix version"
doLast {
props['hotfix'] = String.valueOf(++props['hotfix'])
props.store(propsFile.newWriter(), null)
project.ext.set('versionName', getVersionName(props))
print "Increased hotfix version to ${project.versionName}"
}
}
task commitVersionIncrease(type: Exec) {
commandLine 'git', 'commit', '-am', "Increased to version ${project.versionName} v${project.versionCode}"
doLast {
props.store(propsFile.newWriter(), null)
project.ext.set('versionCode', versionCode)
project.ext.set('versionName', getVersionName(props))
print "Increased to version ${project.versionName} v${project.versionCode}"
}
}
def getVersionName(props) {
int major = props['major'].toInteger()
int minor = props['minor'].toInteger()
int hotfix = props['hotfix'].toInteger()
return "$major.$minor.$hotfix"
}