-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelease.gradle
51 lines (44 loc) · 1.59 KB
/
release.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
import java.util.regex.Pattern
def SNAPSHOT_SUFFIX = "-SNAPSHOT"
def PROPERTIES_FILE = "gradle.properties"
def VERSION_REGEX = "version=(\\d+)\\.(\\d+)\\.(\\d+)(-SNAPSHOT)?"
def updateFile(fileName, regex, updateText) {
def file = file(fileName)
def fileContents = file.getText()
def pattern = Pattern.compile(regex)
def matcher = pattern.matcher(fileContents)
matcher.find()
def updatedFileContents = matcher.replaceAll(updateText)
file.write(updatedFileContents)
}
def updateProjectVersion(newVersion) {
project.setVersion(newVersion)
println("Updated project version to $newVersion")
}
ext {
removeSnapshotFromVersion = {
if (version != null) {
def newVersion = version.minus(SNAPSHOT_SUFFIX)
updateFile(PROPERTIES_FILE, VERSION_REGEX, "version=" + newVersion)
updateProjectVersion(newVersion)
}
}
addSnapshotToVersion = {
if (version != null && !version.contains(SNAPSHOT_SUFFIX)) {
def newVersion = version.plus(SNAPSHOT_SUFFIX)
updateFile(PROPERTIES_FILE, VERSION_REGEX, "version=" + newVersion)
updateProjectVersion(newVersion)
}
}
incrementMinor = {
if (version != null) {
def (major, minor, patch) = version.tokenize('.')
(major, minor) = [major, minor].collect {
it.toInteger()
}
def newVersion = major + "." + (minor + 1) + "." + patch;
updateFile(PROPERTIES_FILE, VERSION_REGEX, "version=" + newVersion)
updateProjectVersion(newVersion)
}
}
}