[英]How to exclude library from all dependencies in Kotlin DSL build.gradle?
I started migration from build.gradle
(Groovy) to build.gradle.kts
(Kotlin DSL).我开始从
build.gradle
(Groovy) 迁移到build.gradle.kts
(Kotlin DSL)。 The thing is that com.google.common.util.concurrent.ListenableFuture
(from com.google.guava
) exists in several dependecies.问题是
com.google.common.util.concurrent.ListenableFuture
(来自com.google.guava
)存在于几个依赖项中。 Because of that build fails with java.lang.RuntimeException: Duplicate class...
error.由于该构建失败,
java.lang.RuntimeException: Duplicate class...
错误。
Previously (when I had build.gradle
in Groovy) this problem was solved with this snippet:以前(当我在 Groovy 中有
build.gradle
时)这个问题是用这个片段解决的:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
But I can't find anything similar using Kotlin DSL.但我无法使用 Kotlin DSL 找到任何类似的东西。 Could you please provide Kotlin alternative for the snippet above or suggest any other solution on how to deal with this?
您能否为上面的代码片段提供 Kotlin 替代方案,或者就如何处理此问题提出任何其他解决方案?
This works with the Gradle Kotlin DSL:这适用于 Gradle Kotlin DSL:
configurations {
all {
exclude(group = "com.google.guava", module = "listenablefuture")
}
}
这可能有效(虽然我还没有尝试过):
configurations.forEach { it.exclude("com.google.guava", "listenablefuture") }
For two group you can use like this:对于两组,您可以这样使用:
configurations.forEach {
it.exclude("com.google.guava", "listenablefuture")
it.exclude(group = "org.jetbrains", module = "annotations")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.