Vin*_*yen 9 testing android android-gradle-plugin
我有2个模块,模块A和模块B。模块B依赖于模块A,模块A通过使用api
配置与模块B共享依赖库。
在模块A内设置测试环境时,我还使用testApi
&androidTestApi
使用共享的测试库来制作模块B。但是,在运行gradle sync之后,我收到了警告消息:WARNING: Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'
。
阅读提供的链接,并说other modules can't depend on androidTest, you get the following warning if you use the androidTestApi configuration
。因此,我必须在示例中在模块B中定义测试库,以跳过此警告。
我对此情况有一些疑问:
api
?非常感谢
Chr*_*nis 10
我这样做的方法是通过创建自定义配置。在您的情况下,在build.gradle
文件模块A中添加:
configurations {
yourTestDependencies.extendsFrom testImplementation
}
dependencies {
// example test dependency
testImplementation "junit:junit:4.12"
// .. other testImplementation dependencies here
}
Run Code Online (Sandbox Code Playgroud)
并在build.gradle
模块B的中添加:
dependencies {
testImplementation project(path: ':moduleA', configuration: 'yourTestDependencies')
}
Run Code Online (Sandbox Code Playgroud)
上面将包括testImplementation
在模块A到模块B中声明的所有依赖项。
这是Chris Margonis(感谢!)在 Kotlin-DSL 中的回答:
// "base" module/project
configurations {
create("testDependencies"){
extendsFrom(configurations.testImplementation.get())
}
}
dependencies {
// example test dependency
testImplementation "junit:junit:4.12"
// .. other testImplementation dependencies here
}
//another module
dependencies {
testImplementation(project(path = ":base", configuration = "testDependencies"))
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1189 次 |
最近记录: |