To add a library as a dependecy for both local and instrumented unit tests I need to add two lines of code to build.gradle
:
testCompile "org.mockito:mockito-core:${mockitoVersion}"
androidTestCompile "org.mockito:mockito-core:${mockitoVersion}"
Is it possible to do this in a single line?
I'm looking for something like:
bothTestCompile "org.mockito:mockito-core:${mockitoVersion}"
You can let configurations extend from other configurations. The code below creates a new configuration, that testCompile
and androidTestCompile
extend from. This way, each dependency of the new configuration will also be a dependency of these configurations.
configurations {
// Create new configuration
bothTestCompile
// Let both configurations extend from 'bothTestCompile'
testCompile.extendsFrom(bothTestCompile)
androidTestCompile.extendsFrom(bothTestCompile)
}
Now you can use the new configuration in your dependencies
closure just like you did in your example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.