Android Gradle在KTS中使用API和Exclude声明一个Variant Build Flavor依赖.&



我正在尝试构建我的应用程序的风格,其中包括一个非常重的依赖关系,并且只会在某些构建中用于测试和离线开发(依赖是Wiremock for Android)。然而,我似乎找不到任何风格的变体依赖声明也使用api()和排除。

在我决定将依赖项移动到构建变体之前,我可以像这样声明依赖项:

dependencies {
//WireMock - Do not put in release builds bc of large size
api("com.github.tomakehurst:wiremock:2.18.0") {
exclude("org.apache.httpcomponents", "httpclient")
exclude("org.ow2.asm", "asm")
exclude("org.json", "json")
}
api("org.apache.httpcomponents:httpclient-android:4.3.5.1")
}

我想把这个依赖限制到我的构建风格中,我简单地称之为"mock",类似于:

dependencies: {
"mockImplementation"(
api("com.github.tomakehurst:wiremock:2.18.0") {
exclude("org.apache.httpcomponents", "httpclient")
exclude("org.ow2.asm", "asm")
exclude("org.json", "json")
}
api("org.apache.httpcomponents:httpclient-android:4.3.5.1")
})
}

这显然是非常错误的,但我不确定如何使用api进行格式化并排除依赖符号,因为我找不到很多例子,当涉及到将这些与构建风格相结合时。

经过一番尝试,我最终得到了:

// WireMock - Do not put in release builds bc of large size, restrict to mock flavors
"mockImplementation"(mockApi("com.github.tomakehurst:wiremock:2.18.0") {
// Using Android Version Instead
exclude("org.apache.httpcomponents", "httpclient")
//Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
exclude("org.ow2.asm", "asm")
//Was getting this warning, so decided to ignore this version included by WireMock.
//Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jar to change the class packages
exclude("org.json", "json")
})
"mockImplementation"(mockApi("org.apache.httpcomponents:httpclient-android:4.3.5.1") {})

注意"mockApi"是必要的,而不是仅仅使用"api"来实际约束变量

相关内容

最新更新