-
Notifications
You must be signed in to change notification settings - Fork 44
/
build.gradle
86 lines (75 loc) · 2.62 KB
/
build.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
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
id 'org.jetbrains.kotlin.jvm' version '2.0.0' apply false
//https://github.com/vanniktech/gradle-maven-publish-plugin
id "com.vanniktech.maven.publish" version "0.29.0" apply false
}
ext {
compileSdk = 34
targetSdk = 31
minSdk = 21
}
def synchronized getVersionProperty(propName, defValue) {
def file = file("version.properties")
def ret = defValue
if (file.exists() && file.canRead()) {
FileInputStream input = new FileInputStream(file)
Properties props = new Properties()
props.load(input)
ret = props.get(propName);
input.close()
}
return ret
}
def getAppVersionName() {
String versionName = getVersionProperty("PROJ_VERSION", "1.0.0")
return versionName
}
def getAppVersionCode() {
String versionName = getAppVersionName()
def versions = versionName.split("\\.")
def updateVersionString = ""
for (int i = 0; i < versions.size(); i++) {
def subString = versions[i]
if (i == 0) {
updateVersionString += subString
continue
} else if (i >= 3) {
break
}
def subNumber = Integer.parseInt(subString)
updateVersionString += String.format("%01d", subNumber)
}
return Integer.parseInt(updateVersionString)
}
task bumpVersion() {
doLast {
def versionName = getAppVersionCode() + 1
def str = versionName.toString()
def length = str.length()
def newVersionName = ""
for (int i = 0; i < length; i++) {
newVersionName += str.charAt(i)
if (i < 2) {
newVersionName += "."
}
}
def versionPropsFile = file('version.properties')
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def oldVersionName = versionProps['PROJ_VERSION']
versionProps['PROJ_VERSION'] = newVersionName
versionProps.store(versionPropsFile.newWriter(), null)
File configFile = new File("README.md")
String exportText = configFile.text
String text = exportText.replaceAll("Lib:"+oldVersionName,"Lib:"+newVersionName)
configFile.write(text)
println("升级版本号完成,versionName = "+newVersionName)
}
}
def appVersionName = getAppVersionName()
group = PROJ_GROUP
version = appVersionName