-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.gradle
100 lines (86 loc) · 2.83 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
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
class ApplicationVersion {
Integer major
Integer minor
Integer patch
Boolean release
ApplicationVersion(Integer major, Integer minor, Integer patch, Boolean release) {
this.major = major
this.minor = minor
this.patch = patch
this.release = release
}
private String getRelease() {
return this.release ? '' : '-SNAPSHOT'
}
String getVersion() {
return "$major.$minor.$patch" + this.getRelease()
}
}
ext.loadVersion = { ->
def versionPropertiesFile = file('version.properties')
if (!versionPropertiesFile.exists()) {
throw new Exception('No version.properties file found')
}
Properties versionProperties = new Properties()
versionPropertiesFile.withInputStream { stream ->
versionProperties.load(stream)
}
return new ApplicationVersion(versionProperties.major.toInteger(),
versionProperties.minor.toInteger(),
versionProperties.patch.toInteger(),
versionProperties.release.toBoolean())
}
tasks.register('majorVersionUpdate') {
group 'versioning'
description 'Bump to next major version'
doFirst {
def versionFile = file('version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'major', type: 'int', operation: '+', value: 1)
entry(key: 'minor', type: 'int', operation: '=', value: 0)
entry(key: 'patch', type: 'int', operation: '=', value: 0)
}
}
}
tasks.register('minorVersionUpdate') {
group 'versioning'
description 'Bump to next minor version'
doFirst {
def versionFile = file('version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'minor', type: 'int', operation: '+', value: 1)
entry(key: 'patch', type: 'int', operation: '=', value: 0)
}
}
}
tasks.register('patchVersionUpdate') {
group 'versioning'
description 'Bump to next patch version'
doFirst {
def versionFile = file('version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'patch', type: 'int', operation: '+', value: 1)
}
project.version = loadVersion().getVersion()
}
}
tasks.register('releaseVersion') {
group 'versioning'
description 'Make the version a release'
doFirst {
def versionFile = file('version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'release', type: 'string', operation: '=', value: 'true')
}
}
}
tasks.register('preReleaseVersion') {
group 'versioning'
description 'Make the version a pre release'
doFirst {
def versionFile = file('version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'release', type: 'string', operation: '=', value: 'false')
}
}
}