Excluding a dependency of a dependency

I’m working with gradle and although I’ve been using exclude with success to remove transitive dependencies I don’t want, I can’t seem to work out how to solve the following.

Let’s assume I have the following dependencies:

org.library:useful:2.0.0 ±-org.library:logging:1.5 ±-org.another-library:tools:1.9


As you can see I have a version conflict between logging 1.5 and logging 1.4. In my configuration I know that I can use exclude do the following:

config(‘org.library:useful:2.0.0’) {

exclude(group: ‘org.library’, module: ‘logging’) }

But how do I say “exclude logging 1.4” that doesn’t come from anything I depend on (in this example it comes from org.another-library:tools:1.9)?

I would suggest excluding at the configuration level. That way, the exclusion will apply regardless of which of your dependencies transitively pulled in the unwanted artifact.

See “50.4.7. Excluding transitive dependencies” in the user guide: http://www.gradle.org/docs/current/userguide/dependency_management.html

Note that in your specific example, gradle would already reject the older version by default. This is described further in “50.2.3. Resolve version conflicts” of the same chapter in the user guide.

What would that exclusion look like in my example please? I need to exclude 1.4 but not 1.5.

I’m using failOnVersionConflict() so the above will not work.

Stack Overflow already has a good answer (I don’t understand your comment on that answer).

PS: Please don’t double-post here and on Stack Overflow.