如何定义变量以排除 build.gradle.kts 中的多个传递依赖项
How do you define variables for excluding multiple transitive dependencies in a build.gradle.kts
我知道在基于 groovy 的 build.gradle 中,您可以定义多个排除项,如所述 here:
dependencies {
def withoutStuff = {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-v13'
exclude group: 'com.android.support', module: 'design-v13'
}
// For Material Datepicker
compile deps.datePicker, withoutStuff
}
但是现在我们如何在基于 kotlin 的 build.gradle.kts 文件中执行此操作?
好的,经过大量搜索、跟踪和错误,我明白了。在依赖之上你可以定义:
val withoutStuff = fun ExternalModuleDependency.() {
exclude(group = "com.android.support", module = "support-v4")
exclude(group = "com.android.support", module = "support-v13")
exclude(group = "com.android.support", module = "design-v13")
}
然后在 dependencies 块中你可以做:
dependencies {
implementation(deps.datePicker, withoutStuff)
...
}
希望对其他人有所帮助,并期待其他答案。
或者,如果您想全局设置排除项,这可能有效:
// android {}
configurations {
implementation {
exclude(group = "androidx.core", module = "app")
exclude(group = "androidx.core", module = "core")
exclude(group = "androidx.appcompat", module = "app")
exclude(group = "com.google.firebase", module = "firebase-iid")
exclude(group = "androidx.test", module = "monitor")
}
}
// dependencies {}
灵感来自:
我知道在基于 groovy 的 build.gradle 中,您可以定义多个排除项,如所述 here:
dependencies {
def withoutStuff = {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-v13'
exclude group: 'com.android.support', module: 'design-v13'
}
// For Material Datepicker
compile deps.datePicker, withoutStuff
}
但是现在我们如何在基于 kotlin 的 build.gradle.kts 文件中执行此操作?
好的,经过大量搜索、跟踪和错误,我明白了。在依赖之上你可以定义:
val withoutStuff = fun ExternalModuleDependency.() {
exclude(group = "com.android.support", module = "support-v4")
exclude(group = "com.android.support", module = "support-v13")
exclude(group = "com.android.support", module = "design-v13")
}
然后在 dependencies 块中你可以做:
dependencies {
implementation(deps.datePicker, withoutStuff)
...
}
希望对其他人有所帮助,并期待其他答案。
或者,如果您想全局设置排除项,这可能有效:
// android {}
configurations {
implementation {
exclude(group = "androidx.core", module = "app")
exclude(group = "androidx.core", module = "core")
exclude(group = "androidx.appcompat", module = "app")
exclude(group = "com.google.firebase", module = "firebase-iid")
exclude(group = "androidx.test", module = "monitor")
}
}
// dependencies {}
灵感来自: