问题
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:
- Why one module should not depends on testing dependencies of other module, although it can depend on normal dependencies defined as
api? - 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