如何从 Kotlin DSL build.gradle 中的所有依赖项中排除库?
How to exclude library from all dependencies in Kotlin DSL build.gradle?
我开始从 build.gradle
(Groovy) 迁移到 build.gradle.kts
(Kotlin DSL)。问题是 com.google.common.util.concurrent.ListenableFuture
(来自 com.google.guava
)存在于多个依赖项中。由于该构建失败并出现 java.lang.RuntimeException: Duplicate class ...
错误。
以前(当我在 Groovy 中有 build.gradle
时)这个问题是用这个片段解决的:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
但我找不到任何类似的使用 Kotlin DSL 的东西。
您能否为上面的代码片段提供 Kotlin 替代方案,或者就如何处理此问题提出任何其他解决方案?
这可能有效(虽然我还没有尝试过):
configurations.forEach { it.exclude("com.google.guava", "listenablefuture") }
这适用于 Gradle Kotlin DSL:
configurations {
all {
exclude(group = "com.google.guava", module = "listenablefuture")
}
}
对于两组你可以这样使用:
configurations.forEach {
it.exclude("com.google.guava", "listenablefuture")
it.exclude(group = "org.jetbrains", module = "annotations")
}
我开始从 build.gradle
(Groovy) 迁移到 build.gradle.kts
(Kotlin DSL)。问题是 com.google.common.util.concurrent.ListenableFuture
(来自 com.google.guava
)存在于多个依赖项中。由于该构建失败并出现 java.lang.RuntimeException: Duplicate class ...
错误。
以前(当我在 Groovy 中有 build.gradle
时)这个问题是用这个片段解决的:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
但我找不到任何类似的使用 Kotlin DSL 的东西。 您能否为上面的代码片段提供 Kotlin 替代方案,或者就如何处理此问题提出任何其他解决方案?
这可能有效(虽然我还没有尝试过):
configurations.forEach { it.exclude("com.google.guava", "listenablefuture") }
这适用于 Gradle Kotlin DSL:
configurations {
all {
exclude(group = "com.google.guava", module = "listenablefuture")
}
}
对于两组你可以这样使用:
configurations.forEach {
it.exclude("com.google.guava", "listenablefuture")
it.exclude(group = "org.jetbrains", module = "annotations")
}