plugins { kotlin("multiplatform") } group = "tech.eritquearcus" version = 0.0.0.0 kotlin { jvm { compilations.all { kotlinOptions.jvmTarget = "1.8" } withJava() testRuns["test"].executionTask.configure { useJUnitPlatform() } } val hostOs = System.getProperty("os.name") val isMingwX64 = hostOs.startsWith("Windows") val nativeTarget = when { hostOs == "Mac OS X" -> macosX64("unix") hostOs == "Linux" -> linuxX64("unix") isMingwX64 -> mingwX64("win") else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } sourceSets { val commonMain by getting { dependencies { } apply(plugin = "org.jetbrains.kotlin.plugin.serialization") } val jvmMain by getting val unixMain by getting val winMain by getting } }
* Try: > Run with --info or --debug option to get more log output. > Run with --scan to get full insights.
* Exception is: org.gradle.api.UnknownDomainObjectException: KotlinSourceSet with name 'unixMain' not found. at org.gradle.api.internal.DefaultNamedDomainObjectCollection.createNotFoundException(DefaultNamedDomainObjectCollection.java:504) at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:333) at org.gradle.kotlin.dsl.NamedDomainObjectCollectionDelegateProvider.provideDelegate(NamedDomainObjectCollectionExtensions.kt:384) at Build_gradle$1$2.execute(build.gradle.kts:53) at Build_gradle$1$2.execute(build.gradle.kts:1) ...
1. 解决方法
用
1 2 3 4 5 6
val unixMain = maybeCreate("unixMain").apply { this.dependsOn(commonMain) } val winMain = maybeCreate("winMain").apply { this.dependsOn(commonMain) }