Means of excluding transitive dependencies seems to have changed between M3 & M8/M9. On purpose?

We have been using M3 since it was released. Recently, I’ve spent some time trying to get us moved to M8 (more recently M9). One of the things I’ve encounted is, whereas I used to to this to exclude Log4j’s optional dependencies:

configurations {
        ...
    }
      dependencies {
        ...
        compile("log4j:log4j:${log4jVersion}") {
            exclude group: "com.sun.jdmk", module: "jmxtools"
            exclude group: "com.sun.jmx", module: "jmxri"
            exclude group: "javax.jms", module: "jms"
            exclude group: "javax.mail", module: "mail"
        }
        ...
    }

this now seem so to be ignored. However, I’ve found that this does the trick:

configurations {
 all*.exclude(group: 'com.sun.jdmk', module: 'jmxtools')
 all*.exclude(group: 'com.sun.jmx', module: 'jmxri')
 all*.exclude(group: 'javax.jms', module: 'jms')
 all*.exclude(group: 'javax.mail', module: 'mail')
        ...
    }
      dependencies {
        ...
 compile group: 'log4j', name: 'log4j', version: "$log4jVersion"
         ...
    }

I looked in the migration guides and nothing jumped out at me. Is this how it should be working today with M8/M9? Or is this a defect?

Thanks,

Jamie

I have this working for me through all recent versions, including m9:

compile ( "org.springframework:spring-core:$springVersion" ) {
    exclude group: 'org.springframework'
    exclude group: 'commons-logging'
}

I have no need to use “modules” in exclude, though.

I tried removing the “module” portion, but that does not work either. As I do not have a repo containing those JARs, Gradle fails with this:

:dm-ctt:compileJava
Download http://nexus01.ad.rds.lexmark.com/content/repositories/thirdparty/javax/jms/jms/1.1/jms-1.1.pom
> Building > :dm-ctt:compileJava > Resolving dependencies ':dm-ctt:compile' > 67Download http://nexus01.ad.rds.lexmark.com/content/repositories/central/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.pom
> Building > :dm-ctt:compileJava > Resolving dependencies ':dm-ctt:compile' > 40Download http://nexus01.ad.rds.lexmark.com/content/repositories/central/com/sun/jmx/jmxri/1.2.1/jmxri-1.2.1.pom
> Building > :dm-ctt:compileJava > Resolving dependencies ':dm-ctt:compile' > 15
FAILURE: Build failed with an exception.
  * What went wrong:
Could not resolve all dependencies for configuration ':dm-ctt:compile'.
> Artifact 'javax.jms:jms:1.1@jar' not found.

Hello Jamie, your original snippet looks correct for me and I am not able to reproduce your problem, as the exclusions work for me as expected. Can you provide an small example build file, that points us to the problem. BTW, I’ve tested your snippet with mavenCentral and log4j Version 1.2.15.

regards, René

Rene,

I’ve cut things down to the minimum and uploaded the project to my GitHub account – https://github.com/jbisotti/GradleM9TransitiveExclusionExample.

In the process, I discovered that if the Cobertura ‘testRuntime’ dependency is commented out, things seem to build just fine. However, with that dependency (though it doesn’t seem to have anything to do with JMS, etc.) the build fails with the message in my previous post.

Thanks,

Jamie

Jamie,

in your example the transitive dependencies are resolved in the test task when the runtime (more precisely testRuntime) configuration is resolved. Though the testRuntime configuration is composed of different other configurations, the exclude definitions are not inherited from them and must be set per configuration explicitly. That’s the reason why your second snippet works.

regards, René

FYI: this change is explained in the M7 Release Notes and Migration Guide.

Rene & Daz,

Thank you for the explanation; sorry I missed it in the M7 documentation. The timely, thorough, responses are greatly appreciated.

Thanks again,

Jamie