summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Igushkin <sergey.igushkin@jetbrains.com>2020-07-13 12:57:32 +0400
committerSergey Igushkin <sergey.igushkin@jetbrains.com>2020-07-14 13:30:21 +0400
commit74fb25edb600aa2269fe3813bf85a673dea3344f (patch)
tree5cf9c1bea9ee16ef95a0f8868de364b59d9907ec
parent868e9f3147800677113a77a623f580dc8f5192be (diff)
downloadkotlin-74fb25edb600aa2269fe3813bf85a673dea3344f.tar.gz
Fix resolving dependency on self in HMPP (KT-39037)
Apply a workaround for grade/gradle#13680 Issue #KT-39037 Fixed (cherry picked from commit 4c273e1fc5b478bf4fb0b13bc8b392e9bf637e21)
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt11
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/build.gradle.kts6
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/gradle.properties2
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/build.gradle.kts62
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonMain/kotlin/CommonMain.kt8
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonTest/kotlin/CommonTest.kt10
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/build.gradle.kts62
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/src/commonMain/kotlin/CommonMain.kt10
-rw-r--r--libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/settings.gradle.kts15
-rw-r--r--libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/GranularMetadataTransformation.kt10
10 files changed, 194 insertions, 2 deletions
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt
index 6c815a6807c..8f1cf5614ac 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt
@@ -524,6 +524,17 @@ class HierarchicalMppIT : BaseGradleIT() {
}
}
+ @Test
+ fun testTransitiveDependencyOnSelf() = with(Project("transitive-dep-on-self-hmpp")) {
+ testDependencyTransformations(subproject = "lib") { reports ->
+ reports.single {
+ it.sourceSetName == "commonTest" && it.scope == "implementation" && "libtests" in it.groupAndModule
+ }.let {
+ assertEquals(setOf("commonMain", "jvmAndJsMain"), it.allVisibleSourceSets)
+ }
+ }
+ }
+
private fun Project.testDependencyTransformations(
subproject: String? = null,
check: CompiledProject.(reports: Iterable<DependencyTransformationReport>) -> Unit
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/build.gradle.kts
new file mode 100644
index 00000000000..37bd9c77326
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/build.gradle.kts
@@ -0,0 +1,6 @@
+allprojects {
+ repositories {
+ mavenLocal()
+ jcenter()
+ }
+} \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/gradle.properties
new file mode 100644
index 00000000000..0ae1e640ff1
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/gradle.properties
@@ -0,0 +1,2 @@
+kotlin.mpp.enableGranularSourceSetsMetadata=true
+kotlin.mpp.enableCompatibilityMetadataVariant=true \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/build.gradle.kts
new file mode 100644
index 00000000000..a6cd31c915a
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/build.gradle.kts
@@ -0,0 +1,62 @@
+plugins {
+ kotlin("multiplatform")
+}
+
+kotlin {
+ jvm()
+ js {
+ browser()
+ }
+
+ sourceSets {
+ val commonMain by getting {
+ dependencies {
+ implementation(kotlin("stdlib-common"))
+ }
+ }
+
+ val commonTest by getting {
+ dependencies {
+ implementation(project(":libtests"))
+ implementation(kotlin("test-common"))
+ implementation(kotlin("test-annotations-common"))
+ }
+ }
+
+ val jvmAndJsMain by creating {
+ dependsOn(commonMain)
+ }
+
+ val jvmAndJsTest by creating {
+ dependsOn(commonTest)
+ }
+
+ val jvmMain by getting {
+ dependsOn(jvmAndJsMain)
+ dependencies {
+ implementation(kotlin("stdlib-jdk8"))
+ }
+ }
+
+ val jvmTest by getting {
+ dependsOn(jvmAndJsTest)
+ dependencies {
+ implementation(kotlin("test-junit"))
+ }
+ }
+
+ val jsMain by getting {
+ dependsOn(jvmAndJsMain)
+ dependencies {
+ implementation(kotlin("stdlib-js"))
+ }
+ }
+
+ val jsTest by getting {
+ dependsOn(jvmAndJsTest)
+ dependencies {
+ implementation(kotlin("test-js"))
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonMain/kotlin/CommonMain.kt
new file mode 100644
index 00000000000..b8a633983b7
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonMain/kotlin/CommonMain.kt
@@ -0,0 +1,8 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package com.example
+
+fun libFun() { }
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonTest/kotlin/CommonTest.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonTest/kotlin/CommonTest.kt
new file mode 100644
index 00000000000..b2aea11ae7c
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/lib/src/commonTest/kotlin/CommonTest.kt
@@ -0,0 +1,10 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package com.example
+
+fun libCommonTestFun() {
+ libtestsFun()
+}
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/build.gradle.kts
new file mode 100644
index 00000000000..28f9c1ad65a
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/build.gradle.kts
@@ -0,0 +1,62 @@
+plugins {
+ kotlin("multiplatform")
+}
+
+kotlin {
+ jvm()
+ js {
+ browser()
+ }
+
+ sourceSets {
+ val commonMain by getting {
+ dependencies {
+ api(project(":lib"))
+ implementation(kotlin("stdlib-common"))
+ }
+ }
+
+ val commonTest by getting {
+ dependencies {
+ implementation(kotlin("test-common"))
+ implementation(kotlin("test-annotations-common"))
+ }
+ }
+
+ val jvmAndJsMain by creating {
+ dependsOn(commonMain)
+ }
+
+ val jvmAndJsTest by creating {
+ dependsOn(commonTest)
+ }
+
+ val jvmMain by getting {
+ dependsOn(jvmAndJsMain)
+ dependencies {
+ implementation(kotlin("stdlib-jdk8"))
+ }
+ }
+
+ val jvmTest by getting {
+ dependsOn(jvmAndJsTest)
+ dependencies {
+ implementation(kotlin("test-junit"))
+ }
+ }
+
+ val jsMain by getting {
+ dependsOn(jvmAndJsMain)
+ dependencies {
+ implementation(kotlin("stdlib-js"))
+ }
+ }
+
+ val jsTest by getting {
+ dependsOn(jvmAndJsTest)
+ dependencies {
+ implementation(kotlin("test-js"))
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/src/commonMain/kotlin/CommonMain.kt
new file mode 100644
index 00000000000..b7c144f0961
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/libtests/src/commonMain/kotlin/CommonMain.kt
@@ -0,0 +1,10 @@
+/*
+ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package com.example
+
+fun libtestsFun() {
+ libFun()
+} \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/settings.gradle.kts
new file mode 100644
index 00000000000..aae5124f5f2
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/transitive-dep-on-self-hmpp/settings.gradle.kts
@@ -0,0 +1,15 @@
+pluginManagement {
+ repositories {
+ mavenLocal()
+ gradlePluginPortal()
+ }
+ plugins {
+ val kotlin_version: String by settings
+ kotlin("multiplatform").version(kotlin_version)
+ }
+}
+
+rootProject.name = "lib-and-app"
+
+include("lib")
+include("libtests") \ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/GranularMetadataTransformation.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/GranularMetadataTransformation.kt
index dddbe39e467..ee51f254cbe 100644
--- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/GranularMetadataTransformation.kt
+++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/GranularMetadataTransformation.kt
@@ -10,6 +10,7 @@ import org.gradle.api.artifacts.*
import org.gradle.api.artifacts.component.*
import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.artifacts.result.ResolvedDependencyResult
+import org.gradle.api.attributes.Attribute
import org.gradle.api.file.FileCollection
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
@@ -108,9 +109,14 @@ internal class GranularMetadataTransformation(
requestedDependencies.forEach { dependency ->
if (dependency !in originalDependencies) {
- modifiedConfiguration = (modifiedConfiguration ?: allSourceSetsConfiguration.copyRecursive()).apply {
- dependencies.add(dependency)
+ modifiedConfiguration = modifiedConfiguration ?: project.configurations.detachedConfiguration().apply {
+ fun <T> copyAttribute(key: Attribute<T>) {
+ attributes.attribute(key, allSourceSetsConfiguration.attributes.getAttribute(key)!!)
+ }
+ allSourceSetsConfiguration.attributes.keySet().forEach { copyAttribute(it) }
+ allSourceSetsConfiguration.extendsFrom.forEach { extendsFrom(it) }
}
+ modifiedConfiguration!!.dependencies.add(dependency)
}
}