diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt index a7051297764..6758e816484 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt @@ -8,7 +8,6 @@ import org.jetbrains.kotlin.gradle.util.modify import org.jetbrains.kotlin.test.KotlinTestUtils import org.junit.Test import java.io.File -import kotlin.test.assertEquals class KotlinAndroidGradleIT : AbstractKotlinAndroidGradleTests(androidGradlePluginVersion = "2.3.0") { @@ -23,36 +22,6 @@ class KotlinAndroid32GradleIT : KotlinAndroid3GradleIT(androidGradlePluginVersio @Test fun testAndroidWithNewMppApp() = with(Project("new-mpp-android")) { - build("printSourceSetDependsOnRelations") { - val dependsOnReportRegex = "(\\w+?) dependsOn \\[(.*?)]".toRegex() - val dependsOnRelations = dependsOnReportRegex - .findAll(output) - .associate { it.groupValues[1] to it.groupValues[2].split(", ").toSet() } - - val expectedDependsOnRelations = listOf( - "androidLibMain" to setOf("commonMain"), - "androidLibDebug" to setOf("commonMain", "androidLibMain"), // compilation - "androidLibRelease" to setOf("commonMain", "androidLibMain"), // compilation - - "androidLibTest" to setOf("commonTest"), - "androidLibTestDebug" to setOf("commonTest"), - "androidLibTestRelease" to setOf("commonTest"), - "androidLibAndroidTestDebug" to setOf("commonTest"), - "androidLibAndroidTest" to setOf("commonTest"), - "androidLibDebugAndroidTest" to setOf("commonTest", "androidLibAndroidTest", "androidLibAndroidTestDebug"), // compilation - "androidLibDebugUnitTest" to setOf("commonTest", "androidLibTest", "androidLibTestDebug"), // compilation - "androidLibReleaseUnitTest" to setOf("commonTest", "androidLibTest", "androidLibTestRelease") // compilation - ) - - for ((sourceSetName, expectedDependsOn) in expectedDependsOnRelations) { - assertEquals( - expectedDependsOn, - dependsOnRelations[sourceSetName], - "source set $sourceSetName should depend on $expectedDependsOn" - ) - } - } - build("assemble", "compileDebugUnitTestJavaWithJavac") { assertSuccessful() diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle index feba04070a4..8ee1a222fcb 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle @@ -51,12 +51,4 @@ kotlin { fromPreset(presets.jvm, 'jvmLib') fromPreset(presets.js, 'jsLib') } -} - -task printSourceSetDependsOnRelations { - doFirst { - kotlin.sourceSets.each { sourceSet -> - println sourceSet.name + " dependsOn " + sourceSet.dependsOn.collect { it.name } - } - } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt index c0007093978..7ccf496e87a 100755 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt @@ -730,9 +730,17 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationT kotlinTask.destinationDir = File(project.buildDir, "tmp/kotlin-classes/$variantDataName") kotlinTask.description = "Compiles the $variantDataName kotlin." - configureSources(kotlinTask, variantData, compilation) - // Register the source only after the task is created and source set relations are built: + // Register the source only after the task is created, because tne task is required for that: compilation.source(defaultSourceSet) + configureSources(kotlinTask, variantData, compilation) + + // In MPPs, add the common main Kotlin sources to non-test variants, the common test sources to test variants + val commonSourceSetName = if (getTestedVariantData(variantData) == null) + KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME else + KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME + project.kotlinExtension.sourceSets.findByName(commonSourceSetName)?.let { + compilation.source(it) + } wireKotlinTasks(project, compilation, androidPlugin, androidExt, variantData, javaTask, kotlinTask) } @@ -756,32 +764,10 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationT private fun configureSources(compileTask: AbstractCompile, variantData: V, compilation: KotlinCompilation?) { val logger = compileTask.project.logger - val commonSourceSet = compilation?.run { - target.project.kotlinExtension.sourceSets.run { - // In MPPs, add the common main Kotlin sources to dependsOn of non-test variants, the common test sources to test variants - val commonSourceSetName = if (getTestedVariantData(variantData) == null) - KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME else - KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME - - findByName(commonSourceSetName)?.also { common -> - getByName(compilation.defaultSourceSetName).dependsOn(common) - } - } - } - - val defaultSourceSet = compilation?.run { - target.project.kotlinExtension.sourceSets.getByName(defaultSourceSetName) - } - for (provider in getSourceProviders(variantData)) { val kotlinSourceSet = provider.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet ?: continue if (compilation != null) { - if (commonSourceSet != null) { - kotlinSourceSet.dependsOn(commonSourceSet) - } - if (kotlinSourceSet != defaultSourceSet) { - defaultSourceSet!!.dependsOn(kotlinSourceSet) - } + compilation.source(kotlinSourceSet) } else { compileTask.source(kotlinSourceSet.kotlin) }