Android gradle androidTestApi & testApi configuration obsoleted

谁说我不能喝 提交于 2020-01-12 14:58:40

问题


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.

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'.

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.

I have some questions on this situation:

  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?

Many thanks


回答1:


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
}

And in the build.gradle of module B add:

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

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



来源:https://stackoverflow.com/questions/52587491/android-gradle-androidtestapi-testapi-configuration-obsoleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!