在与Gradle一起使用依赖关系时如何排除多个组 [英] How to exclude multiple groups when using dependencies with gradle

查看:305
本文介绍了在与Gradle一起使用依赖关系时如何排除多个组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 依赖关系{
compile('com.wdullaer:materialdatetimepicker:3.2.2 '){
exclude group:'com.android.support',module:'support-v4'
exclude group:'com.android.support',module:'design'
}

在android应用程序 build.gradle 文件,当我想依赖远程库时,如何使用排除组语法排除多个组?



虽然上面的代码是正确的,但它有点复杂。有没有更简单的方法?

基本上'exclude'只是一个属于'ModuleDependency'类的方法,它接受'group'和'module'的'Map',并且没有办法传递更多。然而,在这种情况下,您可以使用'Groovy'权限,并且可以使用'列'中的每个'组'来调用'ModuleDependency'上的方法'exclude'并通过当前的组。看看下面的近似代码。

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


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?

解决方案

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 }
}

这篇关于在与Gradle一起使用依赖关系时如何排除多个组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆