[英]Gradle Android, exclude dependency from another module
I have an Android app, who I want to unit test. 我有一个Android应用程序,我想进行单元测试。 With the MVP pattern, I was able to extract a lot of classes outside of the "android world" in order to test them as plain unit tests (with Junit) inside a separate module[1].
使用MVP模式,我能够在“android世界”之外提取很多类,以便在单独的模块[1]中将它们作为普通单元测试(使用Junit)进行测试。 However, I would like to log some messages from those classes.
但是,我想从这些类中记录一些消息。 So I have tried to use
slf4j-api
with the android binding. 所以我试图将
slf4j-api
与android绑定一起使用。 With the intention to provide the simple binding on my tests. 有意在我的测试中提供简单的绑定。 But the " test " module start with complaining that there are two slf4j binding in the classpath and that he is using the android-binding.
但是“ 测试 ”模块开始抱怨类路径中有两个slf4j绑定,并且他正在使用android-binding。
So my question is, How can I exclude the slf4j-android
dependency from the " test " module ? 所以我的问题是,如何从“ 测试 ”模块中排除
slf4j-android
依赖? Here is the build.gradle of my " test " module 这是我的“ 测试 ”模块的build.gradle
evaluationDependsOn(":app")
apply plugin: 'java'
dependencies {
def app = project(':app')
testCompile project(path: ':app', configuration: 'debugCompile')
def debugVariant = app.android.applicationVariants.find({it.name == 'debug'})
testCompile debugVariant.javaCompile.classpath
testCompile debugVariant.javaCompile.outputs.files
testCompile files(app.plugins.findPlugin("com.android.application").getBootClasspath())
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock-api-mockito:1.6.1'
testCompile 'org.assertj:assertj-core:1.7.1'
}
[1] http://blog.blundell-apps.com/how-to-run-robolectric-junit-tests-in-android-studio/ [1] http://blog.blundell-apps.com/how-to-run-robolectric-junit-tests-in-android-studio/
Use the "exclude" attribute to remove dependent libraries. 使用“exclude”属性删除依赖库。 Something like the following:
类似于以下内容:
testCompile 'junit:junit:4.12' { exclude 'slf4j-android' } testCompile'junit:junit:4.12'{exclude'slf4j-android'}
I'm not sure which library you need to exclude it from. 我不确定您需要从哪个库中排除它。 To find out, use gradle to list the library dependencies.
要找到答案,请使用gradle列出库依赖项。
gradle dependencies gradle依赖
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.