使用Closure整理Gradle依赖项

问题描述 投票:1回答:1

我读了关于如何整理gradle依赖关系的this post,实现给出了这样的东西:

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()
}

除了丢失快速修复升级依赖版本。 使用这种方式的缺点,缺点或缺点是什么?

我想对此进行讨论,非常欢迎任何意见或反馈。

android gradle android-gradle dependency-management
1个回答
0
投票

我找到的一个约束是当你使用dependencyGroup声明def时。 它将在本地定义您的组,然后无法从其他gradle文件中调用它。要解决这个问题,您可以使用:

ext.myDependencyGroup = dependencyGroup {
    implementation ...
}
© www.soinside.com 2019 - 2024. All rights reserved.