Search code examples
gradlebuild.gradledependency-managementtransitive-dependency

Gradle: How to allow only specific transitive dependency


I would like to globally disable all transitive dependencies. I am using the following and it works fine.

configurations.all {
    transitive = false
}

Problem is that I need to allow transitive dependencies for one specific dependency. Is there a way to do this?

I tried variations of the following but with no success.

compile("my:dep:xxx") {
    transitive = true
}

Solution

  • Try that :

    configurations.all {
        dependencies.matching { it.group != 'my' || it.name != 'dep' }.all {
            transitive = false
        }
    }