Fix resolving an MPP dependency in custom configurations (KT-32239)
In the `KotlinPlatformType` disambiguation rule, don't prefer `common` when there's a `jvm` or an `androidJvm` variant, as this would conflict with disambiguation rules created by the other plugins, such as Gradle's `java` which will choose `org.gradle.usage=java-api` and lead to ambiguity. Issue #KT-32239 Fixed
This commit is contained in:
+4
-2
@@ -32,10 +32,12 @@ enum class KotlinPlatformType: Named, Serializable {
|
|||||||
if (candidateValues == setOf(androidJvm, jvm))
|
if (candidateValues == setOf(androidJvm, jvm))
|
||||||
closestMatch(androidJvm)
|
closestMatch(androidJvm)
|
||||||
|
|
||||||
if (common in candidateValues)
|
if (common in candidateValues && jvm !in candidateValues && androidJvm !in candidateValues) {
|
||||||
// then the consumer requests common or requests no platform-specific artifacts,
|
// then the consumer requests common or requests no platform-specific artifacts,
|
||||||
// so common is the best match, KT-26834
|
// so common is the best match, KT-26834; apply this rule only when no JVM variant is available,
|
||||||
|
// as doing otherwise would conflict with Gradle java's disambiguation rules and lead to KT-32239
|
||||||
closestMatch(common)
|
closestMatch(common)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
import org.jetbrains.kotlin.gradle.util.*
|
import org.jetbrains.kotlin.gradle.util.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class VariantAwareDependenciesIT : BaseGradleIT() {
|
class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||||
private val gradleVersion = GradleVersionRequired.FOR_MPP_SUPPORT
|
private val gradleVersion = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||||
@@ -315,6 +316,27 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testResolveDependencyOnMppInCustomConfiguration() = with(Project("simpleProject", GradleVersionRequired.FOR_MPP_SUPPORT)) {
|
||||||
|
setupWorkingDir()
|
||||||
|
|
||||||
|
gradleBuildScript().appendText(
|
||||||
|
"\n" + """
|
||||||
|
configurations.create("custom")
|
||||||
|
repositories.maven { setUrl("https://dl.bintray.com/kotlin/kotlin-dev") }
|
||||||
|
dependencies { custom("org.jetbrains.kotlinx:kotlinx-cli:0.2.0-dev-7") }
|
||||||
|
tasks.register("resolveCustom") { doLast { println("###" + configurations.custom.toList()) } }
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
build("resolveCustom") {
|
||||||
|
assertSuccessful()
|
||||||
|
val printedLine = output.lines().single { "###" in it }.substringAfter("###")
|
||||||
|
val items = printedLine.removeSurrounding("[", "]").split(", ")
|
||||||
|
assertTrue(items.toString()) { items.any { "kotlinx-cli-jvm" in it } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun BaseGradleIT.Project.embedProject(other: BaseGradleIT.Project, renameTo: String? = null) {
|
internal fun BaseGradleIT.Project.embedProject(other: BaseGradleIT.Project, renameTo: String? = null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user