Search code examples
gradle-kotlin-dsl

Substituting a dependency module with a compatible replacement


In Gradle Groovy DSL you can easily substitute a dependency module with a compatible replacement as explained in the Gradle user manual. How do you do the same in Gradle Kotlin DSL?


Solution

  • I had also opened an issue at the project's github, which was answered by Github user eskatos. I coded and executed his answer and found that it also works. Here is his code.

    configurations.all {
        resolutionStrategy.eachDependency {
            if (requested.name == "groovy-all") {
                useTarget("${requested.group}:groovy:${requested.version}")
                because("prefer 'groovy' over 'groovy-all'")
            }
            if (requested.name == "log4j") {
                useTarget("org.slf4j:log4j-over-slf4j:1.7.10")
                because("prefer 'log4j-over-slf4j' 1.7.10 over any version of 'log4j'")
            }
        }
    }