gpt4 book ai didi

android - Gradle 多模块依赖 - 一起使用 api 和 testImplementation

转载 作者:行者123 更新时间:2023-12-03 05:30:09 25 4
gpt4 key购买 nike

我有一个只包含测试依赖项的模块,我将这些依赖项公开为 api

// testshared/build.gradle

api libraries.lib1
api libraries.lib2

我在 moduleA 中使用它与 testImplementation project(':testshared')
这是否相当于创建从 testImplementation 扩展的自定义配置并像这样使用它:
// testshared/build.gradle

configurations {
myTestDependencies.extendsFrom testImplementation
}

dependencies {

testImplementation libraries.lib1
testImplementation libraries.lib2

// .. other testImplementation dependencies here
}
// moduleA/build.gradle

testImplementation project(path: ':testshared', configuration: 'myTestDependencies')

如此处所示
https://stackoverflow.com/a/53649718/8681368 ?

最佳答案

如果是 testImplementation ,它足以作为应用程序模块的依赖项。其他 api只有在引用多个模块中的相同依赖项时才应该使用(甚至必须使用)。 testImplementation行为与常规模块依赖项不同,因为它们用于整个其他(测试)应用程序。如果没有应用程序模块,则无法进行集成测试,因为它需要 2 个应用程序。库本身只能进行单元测试。

如果你想要一个额外的文件,只需 apply from: "testshared/build.gradle" .
debugImplementation有时也需要,但 testApi只会导致:

Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.

它总是一个无用的配置,因为每个应用程序模块只有一个测试应用程序。使用 testImplementation连同 api只能在应用程序模块中完成。

关于android - Gradle 多模块依赖 - 一起使用 api 和 testImplementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59663319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com