Just like this code:
dependencies {
compile ('com.wdullaer:materialdatetimepicker:3.2.2') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
}
}
In an android app build.gradle
file, when I want to dependency a remote library, how to use exclude group syntax to exclude multiple groups?
Although the code above is a right way, but it`s a little bit complicated.Is there a simpler way?
Option 1) per-dependency exclude rules. When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com.
Using Command Line Flags Task :compileTestJava > Task :processTestResources NO-SOURCE > Task :testClasses > Task :test > ... To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build.
A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.
compileOnly dependencies are available while compiling but not when running them. This is equivalent to the provided scope in maven. It means that everyone who wants to execute it needs to supply a library with all classes of the CompileOnly library.
Well basically 'exclude' is just a method belongs to 'ModuleDependency' class which accepts a 'Map' of 'group' and 'module' and there's no way to pass more.
However you can use 'Groovy' power in this case and for each 'group' from list to call method 'exclude' on 'ModuleDependency' and to pass current 'group'. Take a look at approximate code below.
compile() { dep ->
[group1, group2].each{ group -> dep.exclude group: group }
}
Example is here:
compile group: 'org.jitsi', name: 'libjitsi', version: '1.0-9-g4b85531', {
[new Tuple('org.opentelecoms.sdp', 'sdp-api'),
new Tuple('junit', 'junit')].each {
exclude group: "${it.get(0)}", module: "${it.get(1)}"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With