androidgradlekotlingradle-kotlin-dslkotlin-dsl

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?


Solution

  • This might work (though I haven't tried it):

    configurations.forEach { it.exclude("com.google.guava", "listenablefuture") }