|
| 1 | +import java.util.regex.Matcher |
| 2 | +import java.util.regex.Pattern |
| 3 | + |
1 | 4 | apply plugin: 'com.android.application' |
2 | 5 | apply plugin: 'com.mxalbert.gradle.jacoco-android' |
3 | 6 | apply plugin: 'dagger.hilt.android.plugin' |
@@ -89,3 +92,68 @@ publishing { |
89 | 92 | tasks.named("publishApkPublicationToMavenLocal") { |
90 | 93 | mustRunAfter(":app:assembleRelease") |
91 | 94 | } |
| 95 | + |
| 96 | +task removeSnapshot { |
| 97 | + doLast { |
| 98 | + println("removeSnapshot") |
| 99 | + |
| 100 | + def file = file("build.gradle") |
| 101 | + def originalFileContent = file.getText() |
| 102 | + |
| 103 | + Pattern pattern = Pattern.compile("versionName \"\\d+\\.\\d+\\.\\d+-SNAPSHOT\"") |
| 104 | + Matcher matcher = pattern.matcher(originalFileContent) |
| 105 | + matcher.find() |
| 106 | + println("match: ${matcher.group()}") |
| 107 | + |
| 108 | + def newVersionName = matcher.group().replace("-SNAPSHOT", "") |
| 109 | + println("newVersionName: ${newVersionName}") |
| 110 | + |
| 111 | + def newFileContent = originalFileContent.replaceFirst("versionName \"\\d+\\.\\d+\\.\\d+-SNAPSHOT\"", newVersionName) |
| 112 | + file.write(newFileContent) |
| 113 | + } |
| 114 | +} |
| 115 | +task getVersionName { |
| 116 | + doLast { |
| 117 | + println android.defaultConfig.versionName |
| 118 | + } |
| 119 | +} |
| 120 | +task bumpVersion { |
| 121 | + doLast { |
| 122 | + println("bumpVersion") |
| 123 | + |
| 124 | + def currentVersionCode = android.defaultConfig.versionCode |
| 125 | + println("currentVersionCode: ${currentVersionCode}") |
| 126 | + |
| 127 | + def newVersionCode = currentVersionCode + 1 |
| 128 | + println("newVersionCode: ${newVersionCode}") |
| 129 | + |
| 130 | + def newVersionName = newVersionCode.toString().substring(0, 1).toInteger() + "." + newVersionCode.toString().substring(1, 4).toInteger() + "." + newVersionCode.toString().substring(4, 7).toInteger() |
| 131 | + println("newVersionName: ${newVersionName}") |
| 132 | + |
| 133 | + def file = file("build.gradle") |
| 134 | + def originalFileContent = file.getText() |
| 135 | + def newFileContent = originalFileContent.replaceFirst("versionCode \\d+", "versionCode ${newVersionCode}") |
| 136 | + newFileContent = newFileContent.replaceFirst("versionName \"\\d+\\.\\d+\\.\\d+\"", "versionName \"${newVersionName}\"") |
| 137 | + file.write(newFileContent) |
| 138 | + } |
| 139 | +} |
| 140 | +task addSnapshot { |
| 141 | + doLast { |
| 142 | + println("addSnapshot") |
| 143 | + |
| 144 | + def file = file("build.gradle") |
| 145 | + def originalFileContent = file.getText() |
| 146 | + |
| 147 | + Pattern pattern = Pattern.compile("versionName \"\\d+\\.\\d+\\.\\d+\"") |
| 148 | + Matcher matcher = pattern.matcher(originalFileContent) |
| 149 | + matcher.find() |
| 150 | + println("match: ${matcher.group()}") |
| 151 | + |
| 152 | + def newVersionName = "${matcher.group().substring(12, matcher.group().length() - 1)}-SNAPSHOT\"" |
| 153 | + println("newVersionName: ${newVersionName}") |
| 154 | + |
| 155 | + def newFileContent = originalFileContent.replaceFirst("versionName \"\\d+\\.\\d+\\.\\d+\"", "versionName ${newVersionName}") |
| 156 | + file.write(newFileContent) |
| 157 | + } |
| 158 | +} |
| 159 | + |
0 commit comments