31

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?

Demigod
  • 5,073
  • 3
  • 31
  • 49

3 Answers3

62

This works with the Gradle Kotlin DSL:

configurations {
    all {
        exclude(group = "com.google.guava", module = "listenablefuture")
    }
}
cstroe
  • 3,740
  • 3
  • 27
  • 16
14

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

configurations.forEach { it.exclude("com.google.guava", "listenablefuture") }
Yoni Gibbs
  • 6,518
  • 2
  • 24
  • 37
0

For two group you can use like this:

configurations.forEach {
            it.exclude("com.google.guava", "listenablefuture")
            it.exclude(group = "org.jetbrains", module = "annotations")
        }
    
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44