-
Notifications
You must be signed in to change notification settings - Fork 44
/
versioning.gradle
116 lines (96 loc) · 3.42 KB
/
versioning.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.text.SimpleDateFormat
tasks.register("incrementVersionMajor") {
doLast {
incrementVersion true, false, false
}
}
tasks.register("incrementVersionMinor") {
doLast {
incrementVersion false, true, false
}
}
tasks.register("incrementVersionPatch") {
doLast {
incrementVersion false, false, true
}
}
tasks.register("enableDatedVersionName") {
enableDatedVersionName()
}
def incrementVersion(maj, min, patch) {
def versionMajor = getProperty('version.versionMajor').toInteger()
def versionMinor = getProperty('version.versionMinor').toInteger()
def versionPatch = getProperty('version.versionPatch').toInteger()
if(maj){
versionMajor++
versionMinor = 0
versionPatch = 0
}
if(min){
versionMinor++
versionPatch = 0
}
if(patch){
versionPatch++
}
def file = file('gradle.properties')
def sb = new StringBuilder()
file.eachLine {line ->
if(line.startsWith('version.versionMajor=')){
sb.append("version.versionMajor=${versionMajor}")
}else if(line.startsWith('version.versionMinor=')){
sb.append("version.versionMinor=${versionMinor}")
}else if(line.startsWith('version.versionPatch=')){
sb.append("version.versionPatch=${versionPatch}")
}else{
sb.append(line)
}
sb.append(System.getProperty("line.separator"))
}
file.text = sb.toString()
}
def enableDatedVersionName() {
def file = file('gradle.properties')
def sb = new StringBuilder()
def versionMajor = getProperty('version.versionMajor').toInteger()
def versionMinor = getProperty('version.versionMinor').toInteger()
def versionPatch = getProperty('version.versionPatch').toInteger()
file.eachLine {line ->
if(line.startsWith('version.versionMajor=')){
sb.append("version.versionMajor=${versionMajor}")
}else if(line.startsWith('version.versionMinor=')){
sb.append("version.versionMinor=${versionMinor}")
}else if(line.startsWith('version.versionPatch=')){
sb.append("version.versionPatch=${versionPatch}")
} else if(line.startsWith('version.useDatedVersionName=false')){
sb.append("version.useDatedVersionName=true")
}else{
sb.append(line)
}
sb.append(System.getProperty("line.separator"))
}
file.text = sb.toString()
}
ext.getBuildVersionName = {
def versionMajor = getProperty('version.versionMajor').toInteger()
def versionMinor = getProperty('version.versionMinor').toInteger()
def versionPatch = getProperty('version.versionPatch').toInteger()
def isDatedVersionNameEnabled = getProperty('version.useDatedVersionName').toBoolean()
if (isDatedVersionNameEnabled) {
def date = getCurrentDate()
return "${versionMajor}.${versionMinor}.${versionPatch}-${date}"
} else {
return "${versionMajor}.${versionMinor}.${versionPatch}"
}
}
ext.getBuildVersionCode = {
def versionMajor = getProperty('version.versionMajor').toInteger()
def versionMinor = getProperty('version.versionMinor').toInteger()
def versionPatch = getProperty('version.versionPatch').toInteger()
return versionMajor * 1000 + versionMinor * 100 + versionPatch
}
static def getCurrentDate() {
def date = new Date()
def sdf = new SimpleDateFormat("dd.MM.yy")
return sdf.format(date)
}