How to exclude multiple groups when using dependencies using gradle

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 the android app build.gradle , when I want to depend on the remote library, how to use the exception group syntax to exclude multiple groups?

Although the above code is correct, but it is a little more complicated. Is there an easier way?

0
source share
1 answer

Well, in principle, "exclude" is just a method that belongs to the "ModuleDependency" class, which accepts a "map" "groups" and "module", and there is no way to pass more.

However, you can use the "Groovy" power in this case and for each "group" from the list to call the "exclude" method on "ModuleDependency" and pass the current "group". Check out the sample code below.

 compile() { dep -> [group1, group2].each{ group -> dep.exclude group: group } } 
+2
source

All Articles