diff --git a/libraries/stdlib/build.gradle.kts b/libraries/stdlib/build.gradle.kts index 26e0ea3c401..7040c442385 100644 --- a/libraries/stdlib/build.gradle.kts +++ b/libraries/stdlib/build.gradle.kts @@ -431,15 +431,13 @@ kotlin { kotlin.srcDir("${jsDir}/test") } - val commonMainSourceSet = commonMain.get() val nativeWasmMain by creating { - dependsOn(commonMainSourceSet) + dependsOn(commonMain.get()) kotlin.srcDir("native-wasm/src") } - val commonTestSourceSet = commonTest.get() val nativeWasmTest by creating { - dependsOn(commonTestSourceSet) + dependsOn(commonTest.get()) kotlin.srcDir("native-wasm/test") } @@ -527,7 +525,7 @@ kotlin { if (kotlinBuildProperties.isInIdeaSync) { val nativeKotlinTestCommon by creating { - dependsOn(commonMainSourceSet) + dependsOn(commonMain.get()) val prepareKotlinTestCommonNativeSources by tasks.registering(Sync::class) { from("../kotlin.test/common/src/main/kotlin") from("../kotlin.test/annotations-common/src/main/kotlin") diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt index 092da201452..c13ceca908d 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt @@ -8,10 +8,8 @@ package org.jetbrains.kotlin.gradle.plugin import org.gradle.api.Action import org.gradle.api.Named import org.gradle.api.file.SourceDirectorySet -import org.jetbrains.kotlin.gradle.dsl.KotlinGradlePluginDsl import org.jetbrains.kotlin.tooling.core.HasMutableExtras -@KotlinGradlePluginDsl interface KotlinSourceSet : Named, HasProject, HasMutableExtras, HasKotlinDependencies { val kotlin: SourceDirectorySet diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppHighlightingTestDataWithGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppHighlightingTestDataWithGradleIT.kt index 200f901421e..fffa25a1ba5 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppHighlightingTestDataWithGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/MppHighlightingTestDataWithGradleIT.kt @@ -58,25 +58,15 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() { // create Gradle Kotlin source sets for project roots: val scriptCustomization = buildString { appendLine() - appendLine("kotlin {") - appendLine( - """ - | fun configureTargetsDefaultDependsOn(sourceSet: org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet) { - | listOf(${cliCompiler.targets.joinToString { "$it()" }}).forEach { - | it.compilations["main"].defaultSourceSet.dependsOn(sourceSet) - | } - | } - | - """.trimMargin() - ) - appendLine(" sourceSets {") + appendLine("kotlin {\n sourceSets {") sourceRoots.forEach { sourceRoot -> if (sourceRoot.kotlinSourceSetName != "commonMain") { appendLine( - """ - | create("${sourceRoot.kotlinSourceSetName}") { + """ create("${sourceRoot.kotlinSourceSetName}") { | dependsOn(getByName("commonMain")) - | configureTargetsDefaultDependsOn(this@create) + | listOf(${cliCompiler.targets.joinToString { "$it()" }}).forEach { + | it.compilations["main"].defaultSourceSet.dependsOn(this@create) + | } | } | """.trimMargin() @@ -95,8 +85,7 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() { } } } - appendLine(" }") - appendLine("}") + appendLine(" }\n}") } gradleBuildScript().appendText("\n" + scriptCustomization) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts index 6858a5ebdaf..98579d984b3 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts @@ -10,9 +10,8 @@ repositories { } kotlin { - val commonMainSourceSet = sourceSets.commonMain.get() val nativeMain by sourceSets.creating { - dependsOn(commonMainSourceSet) + dependsOn(sourceSets["commonMain"]) } targets.withType(KotlinNativeTarget::class.java).all { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-platform-libraries/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-platform-libraries/build.gradle.kts index 50285011fd6..86870d98c8b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-platform-libraries/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-platform-libraries/build.gradle.kts @@ -10,9 +10,8 @@ repositories { } kotlin { - val commonMain by sourceSets.getting val nativeMain by sourceSets.creating { - dependsOn(commonMain) + dependsOn(sourceSets["commonMain"]) } targets.withType(KotlinNativeTarget::class.java).all { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-with-configuration-cache/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-with-configuration-cache/build.gradle.kts index 7e73f99915a..a9df8ce407c 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-with-configuration-cache/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-with-configuration-cache/build.gradle.kts @@ -10,9 +10,8 @@ repositories { } kotlin { - val commonMainSourceSet = sourceSets.commonMain.get() val nativeMain by sourceSets.creating { - dependsOn(commonMainSourceSet) + dependsOn(sourceSets["commonMain"]) } targets.withType(KotlinNativeTarget::class.java).all { diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinMultiplatformSourceSetConventionsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinMultiplatformSourceSetConventionsTest.kt index 51601c0b75d..9aba2ee6a8f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinMultiplatformSourceSetConventionsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinMultiplatformSourceSetConventionsTest.kt @@ -55,9 +55,13 @@ class KotlinMultiplatformSourceSetConventionsTest { fun `test - invoke - allows creating new source set in closure`() { val project = buildProjectWithMPP() project.multiplatformExtension.apply { - val fooSourceSet = sourceSets.create("foo") sourceSets.jvmMain { - dependsOn(fooSourceSet) + /* + When done wrong, expect: + org.gradle.api.internal.AbstractMutationGuard$IllegalMutationException: + NamedDomainObjectContainer#create(String) on KotlinSourceSet container cannot be executed in the current context + */ + dependsOn(sourceSets.create("foo")) } assertEquals(setOf("foo"), sourceSets.jvmMain.get().dependsOn.map { it.name }.toSet())