Fix kotlin-test variants for correct resolution in *DependenciesMetadata
Make Gradle choose the `commonVariant` when a capability-less dependency on kotlin-test is resolved for configurations requesting the common artifacts. Issue #KTIJ-6098 Fixed
This commit is contained in:
@@ -119,11 +119,14 @@ val rootComponent = componentFactory.adhoc("root").apply {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val kotlinTestCapability = "$group:kotlin-test:$version" // add to variants with explicit capabilities when the default one is needed, too
|
||||||
val baseCapability = "$group:kotlin-test-framework:$version"
|
val baseCapability = "$group:kotlin-test-framework:$version"
|
||||||
val implCapability = "$group:kotlin-test-framework-impl:$version"
|
val implCapability = "$group:kotlin-test-framework-impl:$version"
|
||||||
|
|
||||||
val jvmTestFrameworks = listOf("junit", "junit5", "testng")
|
val jvmTestFrameworks = listOf("junit", "junit5", "testng")
|
||||||
|
|
||||||
|
val frameworkCapabilities = mutableSetOf<String>()
|
||||||
|
|
||||||
jvmTestFrameworks.forEach { framework ->
|
jvmTestFrameworks.forEach { framework ->
|
||||||
val (apiVariant, runtimeVariant) = listOf("api", "runtime").map { usage ->
|
val (apiVariant, runtimeVariant) = listOf("api", "runtime").map { usage ->
|
||||||
configurations.create("${framework}${usage.capitalize()}Variant") {
|
configurations.create("${framework}${usage.capitalize()}Variant") {
|
||||||
@@ -134,7 +137,9 @@ jvmTestFrameworks.forEach { framework ->
|
|||||||
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
|
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
|
||||||
}
|
}
|
||||||
outgoing.capability(baseCapability) // C0
|
outgoing.capability(baseCapability) // C0
|
||||||
outgoing.capability("$group:kotlin-test-framework-$framework:$version") // C0
|
outgoing.capability(
|
||||||
|
"$group:kotlin-test-framework-$framework:$version".also { frameworkCapabilities.add(it) }
|
||||||
|
) // C0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runtimeVariant.extendsFrom(apiVariant)
|
runtimeVariant.extendsFrom(apiVariant)
|
||||||
@@ -188,6 +193,18 @@ jvmTestFrameworks.forEach { framework ->
|
|||||||
}.let { components.add(it) }
|
}.let { components.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a consumer's dependency requires a specific test framework (like with auto framework selection), their configurations requesting
|
||||||
|
* "common" artifacts (such as `*DependenciesMetadata` in MPP) should choose this variant anyway. Otherwise, choosing this variant
|
||||||
|
* (from a "pure", capability-less dependency on `kotlin-test` appearing transitively in the dependency graph) along with some
|
||||||
|
* capability-providing *platform* variant leads to incompatible variants being chosen together, causing dependency resolution errors,
|
||||||
|
* see KTIJ-6098
|
||||||
|
*/
|
||||||
|
commonVariant.apply {
|
||||||
|
frameworkCapabilities.forEach(outgoing::capability)
|
||||||
|
outgoing.capability(kotlinTestCapability)
|
||||||
|
}
|
||||||
|
|
||||||
val (jsApi, jsRuntime) = listOf("api", "runtime").map { usage ->
|
val (jsApi, jsRuntime) = listOf("api", "runtime").map { usage ->
|
||||||
configurations.create("js${usage.capitalize()}") {
|
configurations.create("js${usage.capitalize()}") {
|
||||||
isCanBeConsumed = true
|
isCanBeConsumed = true
|
||||||
|
|||||||
+15
@@ -163,6 +163,21 @@ class KotlinSpecificDependenciesIT : BaseGradleIT() {
|
|||||||
"jvmAndJsTestCompileOnlyDependenciesMetadata" to listOf("kotlin-test-common"),
|
"jvmAndJsTestCompileOnlyDependenciesMetadata" to listOf("kotlin-test-common"),
|
||||||
"jvmAndJsTestImplementationDependenciesMetadata" to listOf("!kotlin-test-common"),
|
"jvmAndJsTestImplementationDependenciesMetadata" to listOf("!kotlin-test-common"),
|
||||||
)
|
)
|
||||||
|
),
|
||||||
|
TestCase(
|
||||||
|
/**
|
||||||
|
* Check that in a single-platform project the common metadata configurations resolve the
|
||||||
|
* framework-specific dependency (inferred as JUnit) correctly to the common artifact
|
||||||
|
* KTIJ-6098
|
||||||
|
*/
|
||||||
|
Project("mpp-single-jvm-target"),
|
||||||
|
listOf("commonTestImplementation"),
|
||||||
|
mapOf(
|
||||||
|
"compileTestKotlinJvm" to listOf("kotlin-test-junit"),
|
||||||
|
),
|
||||||
|
mapOf(
|
||||||
|
"commonTestImplementationDependenciesMetadata" to listOf("kotlin-test-common", "kotlin-test-annotations-common")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).forEach { testCase ->
|
).forEach { testCase ->
|
||||||
with(testCase) {
|
with(testCase) {
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
val kotlin_version: String by settings
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform").version(kotlin_version)
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.thirdparty
|
||||||
|
|
||||||
|
expect fun thirdPartyFun(): String
|
||||||
|
|
||||||
|
private fun useStdlibInCommonMain() = listOf(1, 2, 3).joinToString()
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.thirdparty
|
||||||
|
|
||||||
|
actual fun thirdPartyFun(): String = "thirdPartyFun @ jvm"
|
||||||
|
|
||||||
|
fun thirdPartyJvmFun() { }
|
||||||
Reference in New Issue
Block a user