仿写之路-gradle配置(大型项目中)

emm不错

本文主要记录gradle在大型项目中的配置。

工程目录下配置一个.gradle文件

如上图在工程目录下配置一个.gradle文件。用来存储所有用到的第三方sdk的名字和版本号。以后sdk升级只需要修改对应的版本号即可。
之前也配置过一种存储所有第三方sdk的名字和版本号的.gradle,但是感觉没有这个管理起来方便(这里就不贴出来了,需要的小伙伴可以留言)

ext.deps = [:]
def versions = [:]

versions.support = "27.1.1"
versions.rxjava = "2.1.8"
versions.rx_android = "2.0.1"
versions.retrofit = "2.4.0"

versions.gson = "2.8.2"
versions.butterknife = "8.5.1"
versions.guava = "20.0"
versions.guava_android = "24.0-android"
versions.rxlifecycle2 = "2.1.0"
versions.android_arch_lifecycle_ext = "1.1.1"

versions.greendao = "3.2.2"
versions.javapoet = "1.9.0"

versions.fresco = "1.3.0"
versions.animated_gif = "1.3.0"
versions.android_sdk = "4.8.2"

versions.lottie = "2.5.4"

versions.annotation_api = "1.3"
versions.android_processes = "1.0.9"

versions.netty = "4.1.0.CR1"
versions.okhttp = "3.10.0"
versions.rxpermissons2 = "0.9.4@aar"
versions.rxbinding = "2.0.0"

// support 相关的逻辑
def support = [:]
support.annotations = "com.android.support:support-annotations:$versions.support"
support.app_compat = "com.android.support:appcompat-v7:$versions.support"
support.recyclerview = "com.android.support:recyclerview-v7:$versions.support"
support.design = "com.android.support:design:$versions.support"
support.percent = "com.android.support:percent:$versions.support"
support.v4 = "com.android.support:support-v4:$versions.support"
support.v13 = "com.android.support:support-v13:$versions.support"
support.core_utils = "com.android.support:support-core-utils:$versions.support"
support.fragment = "com.android.support:support-fragment:$versions.support"
support.emoji = "com.android.support:support-emoji:$versions.support"
deps.support = support

def retrofit = [:]
retrofit.runtime = "com.squareup.retrofit2:retrofit:$versions.retrofit"
retrofit.gson = "com.squareup.retrofit2:converter-gson:$versions.retrofit"
retrofit.mock = "com.squareup.retrofit2:retrofit-mock:$versions.retrofit"
retrofit.rxjava2 = "com.squareup.retrofit2:adapter-rxjava2:$versions.retrofit"
retrofit.scalars = "com.squareup.retrofit2:converter-scalars:$versions.retrofit"
deps.retrofit = retrofit
deps.okhttp_logging_interceptor = "com.squareup.okhttp3:logging-interceptor:${versions.okhttp_logging_interceptor}"

def rxjava2 = [:]
rxjava2.rxjava = "io.reactivex.rxjava2:rxjava:$versions.rxjava"
rxjava2.rxandroid = "io.reactivex.rxjava2:rxandroid:$versions.rx_android"
deps.rxjava2 = rxjava2

def squareup = [:]
squareup.javapoet = "com.squareup:javapoet:$versions.javapoet"
squareup.okhttp3 = "com.squareup.okhttp3:okhttp:$versions.okhttp"
squareup.leakcanary_no_op = "com.squareup.leakcanary:leakcanary-android-no-op:$versions.leakcanary"
squareup.leakcanary = "com.squareup.leakcanary:leakcanary-android:$versions.leakcanary"
deps.squareup = squareup

def rxlifecycle2 = [:]
rxlifecycle2.android = "com.trello.rxlifecycle2:rxlifecycle-android:$versions.rxlifecycle2"
rxlifecycle2.components = "com.trello.rxlifecycle2:rxlifecycle-components:$versions.rxlifecycle2"
deps.rxlifecycle2 = rxlifecycle2

def android_arch = [:]
android_arch.lifecycle_ext = "android.arch.lifecycle:extensions:$versions.android_arch_lifecycle_ext"
deps.android_arch = android_arch

def netty = [:]
netty.common = "io.netty:netty-common:$versions.netty"
netty.buffer = "io.netty:netty-buffer:$versions.netty"
netty.transport = "io.netty:netty-transport:$versions.netty"
netty.codec = "io.netty:netty-codec:$versions.netty"
deps.netty = netty

//greenrobot 相关
def greenrobot = [:]
greenrobot.greendao = "org.greenrobot:greendao:$versions.greendao"
greenrobot.eventbus = "org.greenrobot:eventbus:$versions.eventbus"
greenrobot.eventbus_process = "org.greenrobot:eventbus-annotation-processor:$versions.eventbus"
deps.greenrobot = greenrobot

def lint = [:]
lint.api = "com.android.tools.lint:lint-api:$versions.lint"
lint.checks = "com.android.tools.lint:lint-checks:$versions.lint"
lint.uast = "com.android.tools.external.org-jetbrains:uast:$versions.lint"
deps.lint = lint


deps.butterknife = "com.jakewharton:butterknife:$versions.butterknife"
deps.butterknife_compiler = "com.jakewharton:butterknife-compiler:$versions.butterknife"
deps.gson = "com.google.code.gson:gson:$versions.gson"
deps.guava_android = "com.google.guava:guava:$versions.guava_android"

deps.annotation_api = "javax.annotation:javax.annotation-api:$versions.annotation_api"
deps.rxpermissons2 = "com.tbruyelle.rxpermissions2:rxpermissions:$versions.rxpermissons2"
deps.rxbinding = "com.jakewharton.rxbinding2:rxbinding:$versions.rxbinding"

ext.deps = deps

library.gradle用来存放各个moudule中重复定义的东西。其它moudule只需要引入该文件即可

apply from: rootProject.file('library.gradle')

dependencies {
    implementation deps.rxjava2.rxjava
}

ps:moudule下的xxx.iml文件一定不要删除,否则会引起一些莫名其妙的错误。

你可能感兴趣的:(仿写之路-gradle配置(大型项目中))