-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
148 lines (134 loc) · 3.47 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath "com.android.tools.build:gradle:${BUILD_GRADLE}"
//Kotlin支持
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN_VERSION}"
//AndroidX支持
classpath "com.android.tools.build.jetifier:jetifier-processor:${JETIFIER}"
//Maven支持
classpath "com.github.dcendents:android-maven-gradle-plugin:${ANDROID_MAVEN_GRADLE_PLUGIN}"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
/**
* release apk name
*/
def releaseName = "demo_v" + getGitVersionName() + "_${releaseTime()}_release.apk"
/**
* debug apk name
*/
def debugName = "demo_v" + getGitVersionName() + "_debug.apk"
/**
* 输出目录
*/
def mOutputs = "$rootDir/outputs/build_" + getGitVersionName()
/**
* release时间
* @return
*/
def releaseTime() {
return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
}
/**
* 获取local本地配置文件
* @return
*/
def getlocalProperty() {
Properties buildProps = new Properties()
buildProps.load(new FileInputStream(file('../local.properties')))
return buildProps
}
/**
* 读取Svn日志
* @return
*/
def getSvnVersionInfo() {
return 'svn log -r HEAD'.execute().text.trim()
}
/**
* 读取Svn Revision Number
* @return
*/
def getSvnRevisionNumber() {
return 'svn info --show-item revision'.execute().text.trim()
}
/**
* 读取Git commit number,作为Version Code
* @return
*/
def gitGitVersionCode() {
try {
return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
}
catch (ignored) {
return 1
}
}
/**
* 读取Git Tag,作为Version Name
* @return
*/
def getGitVersionName() {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return "1.0.0"
}
}
/**
* 读取Git日志
* @return
*/
def getGitVersionInfo() {
return 'git rev-parse --short HEAD'.execute().text.trim()
}
/**
* 获取Git分支名
*/
def getGitBranch() {
return 'git symbolic-ref --short -q HEAD'.execute().text.trim()
}
/**
* 输出日志
*/
def buildLog() {
File outputFile = new File("$rootDir/outputs/build_" + APP_VERSION_NAME)
if (!outputFile.exists()) outputFile.mkdirs()
FileWriter fw = new FileWriter("$rootDir/outputs/build_" + APP_VERSION_NAME + File.separator + "log.txt")
StringBuilder builder = new StringBuilder()
builder.append("[构建时间]=" + new Date().format("yyyy/MM/dd HH:mm", TimeZone.getTimeZone("GMT+08:00")))
builder.append("\r\n")
builder.append("[版本编号]=" + gitGitVersionCode())
builder.append("\r\n")
builder.append("[版本名称]=" + getGitVersionName())
builder.append("\r\n")
builder.append("[提交记录]=" + getGitVersionInfo())
fw.write(builder.toString())
fw.flush()
fw.close()
}