【问题标题】:Gradle Android, exclude dependency from another moduleGradle Android,排除来自另一个模块的依赖
【发布时间】:2015-04-05 00:43:49
【问题描述】:

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

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

【问题讨论】:

标签: android unit-testing gradle android-gradle-plugin build.gradle


【解决方案1】:

使用“exclude”属性删除依赖库。类似于以下内容:

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

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

gradle 依赖

【讨论】:

  • 谢谢,但它不起作用。 slf4j-android 来自 app 项目。所以我必须从testCompile project..debugVariant 之一中排除它。假设我必须将其从debugVariant.javaCompile.classpath 中排除。我该怎么做?
猜你喜欢
  • 2018-03-13
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多