How to manage Dendencies with compile/zip an exclude?


(m.stockhammer) #1

Please can anyone explain me this gradle behaviour. I have a custom configuration:

configurations {
 externalLibs
}
  dependencies {
   externalLibs group:'commons-logging',name:'commons-logging',version:'1.1.1'
}
sourceSets {
 main {
  compileClasspath += configurations.externalLibs
  java { srcDir 'src' }
  resources { srcDir 'src' }
 }
}
task zipSharedLib(type: Zip) {
 from configurations.externalLibs
{
                exclude module: 'commons-logging'
        }
}

I thought the exclude does only apply to the zip task, but if I execute the task, the library is missing on the compile too. I tried another solution for the exclude:

from configurations.externalLibs.files { file ->
  file.name != 'xmlParserAPIs' && file.name != 'jstl' && file.name != 'commons-logging'
 }

And this works as expected: The library is included during the compile but excluded from the zip. Can please someone explain the difference?


(Peter Niederwieser) #2

The syntax you used configures (modifies) the configuration. The exclude syntax for archive tasks is different, and operates on files rather than artifacts. For example:

task zipSharedLib(type: Zip) {
    from(configurations.externalLibs) { // note placement of parens
        exclude '**/commons-logging*'
    }
}

Explicitly adding parens sometimes helps to find such problems.


(m.stockhammer) #3

Ok, thank you. I found another topic where the parentheses problem is explained in more detail.

http://gsfn.us/t/2x24s