[英]Tidying up Gradle dependencies using Closure
我讀了這篇關於如何整理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 ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.