[英]What is the difference between simple and source set dependencies when working with the Kotlin MPP plugin?
I'm using the Kotlin MPP plugin (with .kts
support) and while I've been reading some code I came upon build.gradle.kts
files like this:我正在使用 Kotlin MPP 插件(支持
.kts
),虽然我一直在阅读一些代码,但我发现了build.gradle.kts
文件,如下所示:
kotlin {
sourceSets {
commonMain {
dependencies {
api(kotlinxCollectionsImmutable)
}
}
}
dependencies {
with(Libs) {
commonMainApi(kotlinStdLibCommon)
commonMainApi(kotlinxCoroutinesCommon)
}
}
}
What is the difference between declaring an api
dependency within a sourceSet
compared to declaring a commonMainApi
dependency?与声明
commonMainApi
依赖sourceSet
相比,在sourceSet
声明api
依赖项有什么区别? Is there any?有没有?
No difference.没有不同。 The commonMainApi is just an alternative way of doing the same, and doesn't look to be recommended any more.
commonMainApi 只是执行相同操作的另一种方法,不再推荐使用。 Link - https://kotlinlang.ru/docs/reference/building-mpp-with-gradle.html
链接 - https://kotlinlang.ru/docs/reference/building-mpp-with-gradle.html
Альтернативным способом указания зависимостей является использование встроенного DSL Gradle на верхнем уровне с именами конфигурации, следующими за шаблоном : [translation: Alternatively, dependencies can be declared by specifying configuration names at the top level using the built-in Gradle DSL]
АльтернативнымспособомуказаниязависимостейявляетсяиспользованиевстроенногоDSL摇篮наверхнемуровнесименамиконфигурации,следующимизашаблоном:[翻译:或者,依赖关系可以通过使用在顶层指定配置名称声明内置摇篮DSL]
dependencies {
commonMainApi 'com.example:foo-common:1.0'
jvm6MainApi 'com.example:foo-jvm6:1.0'
}
Interestingly, this document is described as a translation of https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html where this paragraph (about the alternative syntax) is completely missing, so one can only deduce that the English version has been updated and the alternative syntax removed as either not recommended or obsolete at this point.有趣的是,该文档被描述为https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html的翻译,其中这一段(关于替代语法)完全缺失,所以只能推断英文版本已更新,替代语法已被删除,因为此时不推荐或已过时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.