简体   繁体   English

使用 Kotlin MPP 插件时,简单集依赖项和源集依赖项之间有什么区别?

[英]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.

相关问题 「Kotlin 插件版」和「Kotlin Gradle 插件版」有什么区别? - What's the difference between 「Kotlin Plugin Version」 and 「Kotlin Gradle Plugin Version」? 构建 Kotlin MPP iOS 应用程序时出现 XCode 错误 - XCode error when building the Kotlin MPP iOS app 项目依赖和其他依赖之间有什么区别 - What is the difference between a project dependency and other dependencies Gradle:类路径和编译依赖有什么区别? - Gradle: What is the difference between classpath and compile dependencies? 什么是 Android kapt 及其用法? 添加依赖项时Gradle中的anootation处理器和kapt有什么区别? - What is Android kapt and its usage? What's the difference between anootation processor and kapt in Gradle when adding dependencies? Gradle中的签名插件和signingConfigs有什么区别? - What is the difference between signing plugin and signingConfigs in Gradle? “ gradle”和“ gradle插件”有什么区别? - What is the difference between “gradle” and “gradle plugin”? Kotlin 本机 MPP 稳定性警告 - Kotlin native MPP stability warning 创建gradle插件时,将生成的Java或Kotlin源放在哪里? - Where to put generated java or kotlin source when creating a gradle plugin? 分发插件中的 installDist 和内置 java 插件 gradle 有什么区别? - What is the difference between installDist in distribution plugin and build in java plugin, gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM