Why do my dependency excludes stop working when I put them in the parent build script?


(rainer.frey) #1

Apparently dependency exclusions can’t be injected in a multi-project build with a ‘allprojects’ or ‘subprojects’ block. They do work when they are defined directly in the subproject build files. Here are the script files:

‘settings.gradle’:

include "common-server"

‘build.gradle’:

apply plugin: "base"
  allprojects {
 buildDir = "output"
 version = "4.2.0.999"
 repositories {
  mavenCentral()
 }
 configurations {
  all*.exclude group: 'log4j', module: 'log4j'
 }
}

‘common-server/build.gradle’:

apply plugin: "java"
  dependencies {
 compile group:"org.slf4j", name:"slf4j-log4j12", version:"1.6.4"
}

‘gradle :common-server:dependencies’ output:

compile - Classpath for compiling the main sources.
\--- org.slf4j:slf4j-log4j12:1.6.4 [default]
     +--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime]
     \--- log4j:log4j:1.2.16 [compile,master,runtime]

When I remove the configurations block from the root build.gradle, and add it to common-server/build.gradle, it works.

‘common-server/build.gradle’:

apply plugin: "java"
  configurations {
 all*.exclude group: 'log4j', module: 'log4j'
}
dependencies {
 compile group:"org.slf4j", name:"slf4j-log4j12", version:"1.6.4"
}

‘gradle :common-server:dependencies’ output:

compile - Classpath for compiling the main sources.
\--- org.slf4j:slf4j-log4j12:1.6.4 [default]
     +--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime]

(Peter Niederwieser) #2

‘configurations.all*.exclude’ will try to configure the configurations eagerly, before they have been added by the subprojects’ build scripts (by way of applying the ‘java’ plugin). Try this instead:

configurations.all {
  exclude group: 'log4j', module: 'log4j'
}

(rainer.frey) #3

Thanks for the explanation! Subtle, but comprehensible difference.