我正在构建一个带有几个Kotlin Multiplatform模块的项目。作为Gradle 文件显示,为了在这些模块之间共享配置,我创建了一个自定义插件。这个插件应该应用kotlin-multiplatform插件和共享配置,但不幸的是,它无法解析应用多平台配置的kotlin扩展。
我的插件(buildSrc\src\main\kotlin\my.pugin.gradle.kts):
plugins {
kotlin("multiplatform")
}
kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
}
jvm {
val main by compilations.getting {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
}错误:
未解决的参考资料。由于接收方类型不匹配,下列任何候选人都不适用:公共乐趣DependencyHandler.kotlin(模块: String,version: String?=.):org.gradle.kotlin.dsl中定义的任何公共乐趣PluginDependenciesSpec.kotlin(模块: String):在org.gradle.kotlin.dsl中定义的PluginDependencySpec
发布于 2020-10-19 14:38:01
显然,您需要的是添加buildSrc对buildSrc\build.gradle.kts中的kotlin-gradle-plugin的依赖。
dependencies {
//...
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
//...
}编辑: $kotlin_version在此范围内不可用,您需要显式地指定它。
https://stackoverflow.com/questions/64422716
复制相似问题