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:
api
?Many thanks
For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With