-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtasks.gradle
43 lines (36 loc) · 1.13 KB
/
tasks.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
import java.util.regex.Matcher
task clean(type: Delete) {
delete rootProject.buildDir
}
void bumpVersionCodeInFile(File file) {
def text = file.text
def matcher = (text =~ /versionCode ([0-9]+)/)
if (!didMatch(matcher)) {
throw new GradleException("Could not find versionCode in app/build.gradle")
}
def String versionCodeStr = matcher[0][1]
def versionCode = Integer.valueOf(versionCodeStr)
def newVersionCode = versionCode + 1
def newContent = matcher.replaceFirst("versionCode " + newVersionCode)
file.write(newContent)
}
private boolean didMatch(Matcher matcher) {
matcher.size() == 1 && matcher.hasGroup()
}
task('bumpVersionCode') << {
bumpAppVersion()
bumpWearVersion()
}
private void bumpWearVersion() {
def wearGradleFile = file('wear/build.gradle')
if (wearGradleFile.canRead()) {
bumpVersionCodeInFile(wearGradleFile)
}
}
private void bumpAppVersion() {
def appGradleFile = file('app/build.gradle')
if (!appGradleFile.canRead()) {
throw new GradleException("Could not read app/build.gradle");
}
bumpVersionCodeInFile(appGradleFile)
}