18

How can I ignore a specific transitive dependency in Gradle?

For example, many libraries (such as Spring and ...) depend on commons-logging, I want to replace commons-logging with SLF4J (and its jcl-over-slf4j bridge).

Is it any way in my gradle script to mention it once, and not for each dependency which depends on commons-logging?

I was thinking of an script, iterating on all dependencies and adding some exclude on all of them, is there any better solution? And how that script be like?

Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69
  • Please try resolution strategy : http://stackoverflow.com/questions/23124509/how-to-exclude-specific-jars-from-web-inf-lib/30393301#30393301 – smilyface May 22 '15 at 09:39

2 Answers2

21
configurations {
    compile.exclude group: 'commons-logging'
}
Ori Dar
  • 18,687
  • 5
  • 58
  • 72
18

Came here with the same problem but ended up using the following to do an actual replace. Posting it for completeness' sake.

configurations.all {
    resolutionStrategy.eachDependency {
        if(it.requested.name == 'commons-logging') {
            it.useTarget 'org.slf4j:jcl-over-slf4j:1.7.7'
        }
    }
}
user2543253
  • 2,143
  • 19
  • 20