Gradle Android,排除另一个模块的依赖

ger*_*s.b 5 android unit-testing gradle build.gradle android-gradle-plugin

我有一个 Android 应用程序,我想对其进行单元测试。通过 MVP 模式,我能够在“android 世界”之外提取许多类,以便在单独的模块中将它们作为普通单元测试(使用 Junit)进行测试[1]。但是,我想记录这些课程的一些消息。所以我尝试slf4j-apiandroid绑定一起使用。旨在为我的测试提供简单的绑定。但是“ test ”模块首先抱怨类路径中有两个 slf4j 绑定,并且他正在使用 android 绑定。

所以我的问题是,如何slf4j-android从“测试”模块中排除依赖项?这是我的“测试”模块的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'

}
Run Code Online (Sandbox Code Playgroud)

[1] http://blog.blundell-apps.com/how-to-run-robolectric-junit-tests-in-android-studio/

And*_*Guy 0

使用“排除”属性删除依赖库。像下面这样:

testCompile 'junit:junit:4.12' { 排除 'slf4j-android' }

我不确定您需要将其从哪个库中排除。要找到答案,请使用 gradle 列出库依赖项。

梯度依赖