Fix resolving dependency on self in HMPP (KT-39037)
Apply a workaround for grade/gradle#13680 Issue #KT-39037 Fixed
This commit is contained in:
+11
@@ -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(
|
private fun Project.testDependencyTransformations(
|
||||||
subproject: String? = null,
|
subproject: String? = null,
|
||||||
check: CompiledProject.(reports: Iterable<DependencyTransformationReport>) -> Unit
|
check: CompiledProject.(reports: Iterable<DependencyTransformationReport>) -> Unit
|
||||||
|
|||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
|
kotlin.mpp.enableCompatibilityMetadataVariant=true
|
||||||
+62
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -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() { }
|
||||||
+10
@@ -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()
|
||||||
|
}
|
||||||
+62
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -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()
|
||||||
|
}
|
||||||
+15
@@ -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")
|
||||||
+8
-2
@@ -10,6 +10,7 @@ import org.gradle.api.artifacts.*
|
|||||||
import org.gradle.api.artifacts.component.*
|
import org.gradle.api.artifacts.component.*
|
||||||
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
||||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||||
|
import org.gradle.api.attributes.Attribute
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
@@ -108,9 +109,14 @@ internal class GranularMetadataTransformation(
|
|||||||
|
|
||||||
requestedDependencies.forEach { dependency ->
|
requestedDependencies.forEach { dependency ->
|
||||||
if (dependency !in originalDependencies) {
|
if (dependency !in originalDependencies) {
|
||||||
modifiedConfiguration = (modifiedConfiguration ?: allSourceSetsConfiguration.copyRecursive()).apply {
|
modifiedConfiguration = modifiedConfiguration ?: project.configurations.detachedConfiguration().apply {
|
||||||
dependencies.add(dependency)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user