[英]Excluding jars via Gradle in unit tests
我使用fileTree()
包含了另一个项目中的一些本地构建的库:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
}
对于单元测试,我想使用自己的模拟类而不是这些jar。 如何让testImplementation
配置为不使用这些jar文件,而是使用源层次结构之外的类似名称的类?
默认情况下, testImplementation
配置从implementation
1扩展,因此添加到implementation
每个依赖项都将出现在testImplementation
。
因此,最好的选择是将这些特定的依赖项声明为不同的配置,我们称其为extraDeps
,然后将其添加到compileClasspath
配置中:
configurations {
extraDeps
compileClasspath.extendsFrom(extraDeps)
}
dependencies {
extraDeps fileTree(dir: 'libs', include: ['*.jar'])
}
这给您带来以下优点:
implementation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.