Confusing exclusion in configuration


I faced with strange behavior of dependency exclusion.
Here an example:

apply plugin: "java"

repositories {

configurations {
    compile.exclude group: 'org.apache.logging.log4j'

dependencies {
     runtime "org.apache.logging.log4j:log4j-jul:2.5"

When I run “gradle dependencies --configuration runtime” I get

runtime - Runtime dependencies for source set ‘main’.
No dependencies

I do not know whether it a bug or not but it looks rather weird for me.
I make an exclusion from compile configuration and it is applied to the runtime comfiguration too.

Can anyone explain is this correct behavior or not?

Looks good to me. You have effectively specififed an empty configuration set. Once you add another dependency to runtime, it will display what you expect.

But why runtime configuration is empty in this case? I added log4j-jul explicitly to runtime. To my mind it should be shown despite of exclusion in compile configuration.
Maybe I am losing something here. Maybe a configuration extends exclude rules from the extended configuration but I can’t find anything in documentation about this.

I see your point - it is a good question. I think what is happening (a Gradle dev can explain this better), is that the resolver rules are inherited (because runtime extends from compile).

The behavior that excludes are inherited is called out in this section of the user guide:

23.4.7. Excluding transitive dependencies
If you define an exclude for a particular configuration, the excluded transitive dependency will be filtered for all dependencies when resolving this configuration or any inheriting configuration.

However, this is specifically listed in the transitive dependency section likely because the expectation is that you’re excluding dependencies you are not able to control directly.

1 Like

Thanks a lot. This part of documentation was skipped while read in hurry.