Android Gradle androidTestApi& testApi配置已过时 [英] Android gradle androidTestApi & testApi configuration obsoleted

查看:1071
本文介绍了Android Gradle androidTestApi& testApi配置已过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个模块,模块A和模块B.模块B依赖于模块A,模块A通过使用api配置与模块B共享依赖库.

I got 2 modules, module A and module B. Module B depends on module A, module A shares dependency libraries to module B by using api configuration.

在模块A内设置测试环境时,我也使用testApi& androidTestApi使用共享测试库制作模块B.但是,在运行gradle sync之后,我得到了警告消息:WARNING: Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.

When setting up test environment, inside module A, I also use testApi & androidTestApi to make module B using shared test libraries. However, after running gradle sync, I got warning message: WARNING: Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.

阅读提供的链接,并说.因此,我必须在示例中在模块B中定义测试库,以跳过此警告.

Read the provided link and it said that other modules can't depend on androidTest, you get the following warning if you use the androidTestApi configuration. Therefore, I must define test libraries in module B in my example for skipping this warning.

我对此情况有疑问:

  1. 为什么一个模块尽管可以依赖于定义为api的常规依赖关系,却不应该依赖于测试另一个模块的依赖关系?
  2. 我们是否仍要强制模块B依赖模块A的测试库,而无需在模块B中再次定义这些库?
  1. Why one module should not depends on testing dependencies of other module, although it can depend on normal dependencies defined as api?
  2. Do we have anyway to force module B depends on test libraries of module A without defined these libraries again in module B?

非常感谢

推荐答案

我这样做的方法是创建一个自定义配置.在您的情况下,在build.gradle文件模块A中添加:

The way I did this was by creating a custom configuration. In your case inside the build.gradle file module A add:

configurations {
    yourTestDependencies.extendsFrom testImplementation
}

dependencies {
    // example test dependency
    testImplementation "junit:junit:4.12"
    // .. other testImplementation dependencies here
}

然后在模块B的build.gradle中添加:

And in the build.gradle of module B add:

dependencies {
    testImplementation project(path: ':moduleA', configuration: 'yourTestDependencies')
}

以上内容将包含在模块A到模块B中声明的所有testImplementation依赖项.

The above will include all testImplementation dependencies declared in module A to module B.

这篇关于Android Gradle androidTestApi& testApi配置已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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