Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: exclude and include multiple groups/modules in single line from compile closure

Tags:

gradle

this syntax may be not yet provided but I am asking to avoid redundant code. Right now I am excluding jars like this

 compile ('com.mygroup:myJar:0.1.1-M1-SNAPSHOT+') {
    exclude group: 'org.apache.xmlgraphics'
    exclude group:'org.apache.avalon.framework'
    exclude group:'net.engio'
    exclude group: 'com.google.guava'
}

How can i exclude multiple groups/modules on a single line of code, for example, this syntax

compile ('com.mygroup:myJar:0.1.1-M1-SNAPSHOT+'){
    exclude group: ['org.apache.xmlgraphics', 'org.apache.avalon.framework', 'net.engio', 'com.google.guava']
}

Or is there any other short code which does the same thing.

Thank You.

like image 767
Rahogata Avatar asked Jul 09 '15 07:07

Rahogata


People also ask

What is exclude group in Gradle?

Within the closure we call exclude , passing: group the group of the artifact we want to exclude. module the name of the artifact we want to exclude. This is equivalent to the name used to declare a dependency in Gradle.

Where does Gradle download dependencies from?

At runtime, Gradle will locate the declared dependencies if needed for operating a specific task. The dependencies might need to be downloaded from a remote repository, retrieved from a local directory or requires another project to be built in a multi-project setting. This process is called dependency resolution.

Where are Gradle dependencies defined?

The Gradle build pulls all dependencies down from the Maven Central repository, as defined by the repositories block. Let's focus on how we can define dependencies.

What is transitive false in Gradle?

If you set transitive=false, then the io. fabric. sdk. android. Fabric class will not be found at compile time.


1 Answers

You could do something like this:

compile ('com.mygroup:myJar:0.1.1-M1-SNAPSHOT+'){
    ['org.apache.xmlgraphics', 'org.apache.avalon.framework', 'net.engio', 'com.google.guava'].each {
        exclude group: it
    }
}

Note that this is leveraging a Groovy feature, not a Gradle feature.

Note also that I don't believe that include is a thing in this context (see the method summary here).

like image 134
Oliver Charlesworth Avatar answered Nov 08 '22 00:11

Oliver Charlesworth