Android 使用闭包整理渐变依赖项

Android 使用闭包整理渐变依赖项,android,gradle,android-gradle-plugin,dependency-management,Android,Gradle,Android Gradle Plugin,Dependency Management,我读过关于如何整理gradle依赖关系的文章,实现给出了如下内容: def dependencyGroup(Closure closure) { closure.delegate = dependencies return closure } def ui = dependencyGroup { implementation "com.android.support:appcompat-v7:27.0.0" implementation "com.android

我读过关于如何整理gradle依赖关系的文章,实现给出了如下内容:

def dependencyGroup(Closure closure) {
    closure.delegate = dependencies
    return closure
}

def ui = dependencyGroup {
    implementation "com.android.support:appcompat-v7:27.0.0"
    implementation "com.android.support.constraint:constraint-layout:1.1.0-beta3"
    implementation "com.android.support:design:27.0.0"
}

def network = dependencyGroup {
    implementation "com.squareup.moshi:moshi-adapters:1.5.0"
    implementation "com.squareup.retrofit2:retrofit:2.3.0"
}

dependencies {
    ui()
    network()
}
此外,还失去了升级依赖项版本的快速修复功能。
使用这种方法的缺点、缺点或缺点是什么


我想就此进行讨论,欢迎发表任何意见或反馈。

我发现的一个限制是当您使用
def
声明一个
dependencyGroup
时 它将在本地定义您的组,然后无法从其他gradle文件调用它。要解决此问题,您可以使用:

ext.myDependencyGroup = dependencyGroup {
    implementation ...
}

您所说的“失去升级依赖项版本的快速修复”是什么意思?从我所看到的,这只是一个DSL糖。我指的是对依赖项字符串的lint检查。通知您有新版本的功能。@crgarridos那么,您更喜欢什么?你仍然使用这种方法吗?