Skip to content

Commit 3db50e0

Browse files
committed
升级gradle kotlin配置,versionCode和Name使用git commit次数和tag标记
1 parent e084397 commit 3db50e0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/build.gradle

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ apply plugin: 'kotlin-kapt'
66

77
apply plugin: "androidx.navigation.safeargs"
88

9+
//定义使用当前分支的commit次数作为int值,用于versionCode
10+
static def getGitVersionCode() {
11+
return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
12+
}
13+
//使用git中的tag作为versionName
14+
static def getGitVersionName() {
15+
//因为指令获取的是 v1.1.1-13-ge084397 格式的,所以需要有效部分即可
16+
return 'git describe --tags'.execute().text.trim().substring(0,6)
17+
}
18+
919
android {
1020
compileSdkVersion 29
11-
buildToolsVersion = '29.0.0'
21+
buildToolsVersion = '29.0.1'
1222

1323
defaultConfig {
1424
applicationId "org.zhiwei.jetpack"
1525
minSdkVersion 21
1626
targetSdkVersion 29
17-
versionCode 2
18-
versionName "1.1.2"
27+
versionCode getGitVersionCode()
28+
versionName getGitVersionName()
1929
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2030

2131

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.40'
4+
ext.kotlin_version = '1.3.41'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.4.1'
10+
classpath 'com.android.tools.build:gradle:3.4.2'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0"
1313

0 commit comments

Comments
 (0)