I'm including some locally-built libs from another project by using fileTree()
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
}
For unit testing, I want to use my own mock classes instead of those jars. How can I have the testImplementation
configure not use those jar files and instead use similarly-named classes out of my source hierarchy?
By default the testImplementation
configuration extends from the implementation
one so every dependency added to implementation
will be present in testImplementation
.
So the best option is to declare these specific dependencies into a different configuration, let's call it extraDeps
, which you then add to the compileClasspath
configuration:
configurations {
extraDeps
compileClasspath.extendsFrom(extraDeps)
}
dependencies {
extraDeps fileTree(dir: 'libs', include: ['*.jar'])
}
This gives you the following advantages:
implementation
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.