简体   繁体   English

如何从 Kotlin DSL build.gradle 中的所有依赖项中排除库?

[英]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.

相关问题 如何将保护级别 build.gradle 的文件从 Gradle Groovy 迁移到 Gradle Kotlin DSL - How to migrate protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL 如何在 Android Studio Bumblebee 中将 build.gradle 从 Groovy 迁移到 Kotlin DSL? - How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee? 如何在build.gradle中使用不同的依赖关系? - How to use different dependencies in build.gradle? 如何从build.gradle读取库的versionName? - How to read a library's versionName from build.gradle? 找不到Gradle DSL方法:'compile()'-依赖项已在模块级别build.gradle中 - Gradle DSL method not found: 'compile()' - Dependencies are in Module level build.gradle already 如何在build.gradle中指定admob库? - How to specify admob library in build.gradle? 如何将库导入 build.gradle - How to import library to build.gradle 如何在gradle的build.gradle依赖项中使用“提供”关键字 - How to use the “provided” keyword in gradle's build.gradle dependencies 在 Android Gradle 构建中,如何从包含的 jar 文件中排除依赖项? - In an Android Gradle build, how to exclude dependencies from an included jar file? 如何在build.gradle(Module app)中排除模块? - how to exclude module in build.gradle(Module app)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM