配置全局参数
根目录build.gradle文件:
主要关注ext部分
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.61'
repositories {
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
//base version
compileSdkVersion = 28
buildToolsVersion = "28.0.2"
minSdkVersion = 19
targetSdkVersion = 26
versionCode = gitVersionCode()
versionName = gitVersionTag()
leanback = "com.android.support:leanback-v17:27.1.1"
annotation = "com.android.support:support-annotations:27.1.1"
v13 = "com.android.support:support-v13:27.1.1"
//kotlin
kotlinStdlibJDK7 = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// arch
lifecycle = "android.arch.lifecycle:extensions:1.1.1"
// exoplayer
exoplayer_version = "2.8.4"
exoplayer = "com.google.android.exoplayer:exoplayer:$exoplayer_version"
exoplayer_core = "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
exoplayer_hls = "com.google.android.exoplayer:exoplayer-hls:$exoplayer_version"
exoplayer_ui = "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
multidex = "com.android.support:multidex:1.0.3"
file_chooser = "com.obsez.android.lib.filechooser:filechooser:1.1.10"
//okhttp3
okhttp3 = "com.squareup.okhttp3:okhttp:3.11.0"
loggingInterceptor = "com.squareup.okhttp3:logging-interceptor:3.11.0"
//retrofit
retrofit = "com.squareup.retrofit2:retrofit:2.4.0"
gsonConvert = "com.squareup.retrofit2:converter-gson:2.4.0"
glide = "com.github.bumptech.glide:glide:3.7.0"
logger = "com.orhanobut:logger:2.2.0"
permission = "com.github.hotchemi:permissionsdispatcher:3.2.0"
permission_processor = "com.github.hotchemi:permissionsdispatcher-processor:3.2.0"
fhttpserver = "cn.hotapk:fhttpserver:0.2.0"
rxbus = "com.blankj:rxbus:1.5"
libaums = "com.github.mjdev:libaums:0.5.5"
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def gitVersionCode() {
def cmd = 'git rev-list HEAD --first-parent --count'
cmd.execute().text.trim().toInteger()
}
def gitVersionTag() {
def cmd = 'git describe --tags --long --always --dirty=-dev'
def version = cmd.execute().text.trim()
return version
}
在项目的build.gradle里面使用:
如下 rootProject.ext+你要引入的配置参数
configurations.all {
resolutionStrategy.force rootProject.ext.okhttp3
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.kotlinStdlibJDK7
implementation rootProject.ext.leanback
implementation rootProject.ext.lifecycle
implementation rootProject.ext.exoplayer
implementation rootProject.ext.exoplayer_core
implementation rootProject.ext.exoplayer_hls
implementation rootProject.ext.exoplayer_ui
implementation rootProject.ext.multidex
implementation rootProject.ext.file_chooser
implementation rootProject.ext.retrofit
implementation rootProject.ext.gsonConvert
implementation rootProject.ext.loggingInterceptor
implementation rootProject.ext.glide
implementation rootProject.ext.logger
implementation rootProject.ext.permission
implementation rootProject.ext.v13
implementation rootProject.ext.fhttpserver
implementation rootProject.ext.rxbus
implementation rootProject.ext.libaums
annotationProcessor rootProject.ext.permission_processor
testImplementation 'junit:junit:4.12'
}