generated from spring-black/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversioning.gradle
126 lines (91 loc) · 2.2 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
117
118
119
120
121
122
123
124
125
126
/**
*
* Auto-magically handles version based on semantic versioning.
* Version information is stored and read from "versioning.properties".
*
* Setup:
*
* 1. Configure build.gradle with the following at a minimum:
*
* apply from: 'versioning.gradle'
* version = ext.getVersion()
*
* 2. Create a file called "version.properties" with the following three lines:
*
* MAJOR=0
* MINOR=0
* PATCH=5
*
* Usage:
*
* $ gradle bump major (i.e.: 1.0.0 to 2.0.0)
* $ gradle bump minor (i.e.: 1.1.0 to 1.2.0)
* $ gradle bump patch (i.e.: 1.0.1 to 1.0.2)
*
*/
gradle.allprojects {
/**
*
* Exposes the function bump() to all projects and can be called manually
* or via the tasks define below.
*
* Pass the mode as an agument with one of: MAJOR, MINOR or PATCH.
*
*/
ext.bump = { mode ->
def versionFile = file('version.properties')
def build = new Properties()
versionFile.withReader {
build.load(it)
}
build[mode] = (Integer.parseInt(build[mode]) + 1).toString()
System.out.println 'Bumping to "' + build
versionFile.withWriter { build.store(it, "This file is now managed by gradle!") }
}
/**
*
* Returns the version string parsed from "version.properties".
*
*/
ext.getVersion = {
def versionFile = file('version.properties')
def build = new Properties()
versionFile.withReader {
build.load(it)
}
return build.MAJOR + '.' + build.MINOR + '.' + build.PATCH
}
/**
*
* Increases version <major>.minor.patch by one.
*
*/
task('bump major') {
group = 'versioning'
doLast {
bump('MAJOR')
}
}
/**
*
* Increases version major.<minor>.patch by one.
*
*/
task('bump minor') {
group = 'versioning'
doLast {
bump('MINOR')
}
}
/**
*
* Increases version major.minor.<patch> by one.
*
*/
task('bump patch') {
group = 'versioning'
doLast {
bump('PATCH')
}
}
}