简体   繁体   中英

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). The thing is that com.google.common.util.concurrent.ListenableFuture (from com.google.guava ) exists in several dependecies. Because of that build fails with java.lang.RuntimeException: Duplicate class... error.

Previously (when I had build.gradle in Groovy) this problem was solved with this snippet:

configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

But I can't find anything similar using Kotlin DSL. Could you please provide Kotlin alternative for the snippet above or suggest any other solution on how to deal with this?

This works with the 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")
        }
    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM