Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle multiple compile dependencies syntax

I am trying to declare a compile dependency in Gradle 1.12, with multiple items that shares the same exclude clauses (this is to avoid repeating the exclusion everywhere). I know I can do something like this:

configurations {
    compile.exclude group: 'com.google.gwt'
    all*.exclude group: 'com.google.guava'
}

but this will affect ALL configurations. What I want is something like this (which does not work in Gradle 1.12 as written below):

compile (
         ["org.jboss.errai:errai-data-binding:2.4.4.Final"]
        ,["org.jboss.errai:errai-data-ioc:2.4.4.Final"]
    ){
        exclude group: 'com.google.gwt' 
        exclude group: 'com.google.guava'
    }

so I can gather together all dependencies for which I need exclusion in one place, and still be able to have elsewhere this:

compile 'com.google.guava:guava:17.0'

Update: Just to clarify, my only goal is to replace this piece of code:

compile ('bla.bla.bla:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('boo.boo.boo:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('uh.uh.uh:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('oh.oh.oh:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}

with something short and sweet like this (not working currently):

compile( 'bla.bla.bla:1.0'
        ,'boo.boo.boo:1.0'
        ,'uh.uh.uh:1.0'
        ,'oh.oh.oh:1.0'
)
{
    exclude 'same.component:1.0' //Only once! Sweet!
}
like image 400
Hristo Stoyanov Avatar asked May 07 '14 04:05

Hristo Stoyanov


1 Answers

There is no way to have per-dependency excludes while still being able to use the compile 'com.google.guava:guava:17.0' syntax. configurations.compile.exclude ... will only affect the compile configuration (and configurations inheriting from it), and is almost always preferable over per-dependency excludes.

Another solution is to factor out dependency declarations with something like:

ext.libs = [
    error_data_ioc: dependencies.create("org.jboss.errai:errai-data-ioc:2.4.4.Final") {
        exclude group: 'com.google.gwt' 
        exclude group: 'com.google.guava'
    }
]

Then you can reuse these declarations wherever you need them (e.g. dependencies { compile libs.error_data_io }; also works from a subproject). If you really wanted, you could also share the same { exclude ... } block among multiple declarations (by assigning it to a local variable).

like image 113
Peter Niederwieser Avatar answered Oct 24 '22 17:10

Peter Niederwieser