Use because() on an exclude

Gradle 4.6 introduces because() to specify why a dependency is added to a configuration.

This is nice, but why a dependency is added is, most of the time, obvious. What’s often not obvious is why a transitive dependency is excluded. Is there a way to specify a reason on an exclude? Something like

    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude(module: 'junit') {
            because 'we want to use JUnit 5 and not JUnit 4'
1 Like

Curious about your thoughts @jendrik and company.

That’s unfortunately not possible at the moment. We currently only show modules that have been selected in the dependency result/report/build scan. During dependency resolution, only these things have a node in the dependency graph to which the reasons are attached.

Adding a reason for why something is not in the result is a larger feature addition (how do we transport this information from the declaration to the result? How/where do we present it in the result?). Still I agree that it is useful and we might add something along these lines in the future.

Just today I came across a situation where I wished I could express exactly that. I think this feature would be a great addition.