[Gradle] Add tests for KT-31468 Targets disambiguation doesn't work if
a depending multiplatform module uses `withJava()` mode ^KT-31468
This commit is contained in:
+23
@@ -273,6 +273,29 @@ class HierarchicalMppIT : KGPBaseTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@GradleTest
|
||||
@DisplayName("Test that disambiguation attribute of Kotlin JVM Target is propagated to Java configurations")
|
||||
fun testMultipleJvmTargetsWithJavaAndDisambiguationAttributeKt31468(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
projectName = "kt-31468-multiple-jvm-targets-with-java",
|
||||
gradleVersion = gradleVersion
|
||||
) {
|
||||
build("assemble", "testClasses") {
|
||||
assertTasksExecuted(
|
||||
":dependsOnPlainJvm:compileKotlinJvm",
|
||||
":dependsOnPlainJvm:compileJava",
|
||||
":dependsOnJvmWithJava:compileKotlinJvm",
|
||||
":dependsOnJvmWithJava:compileJava",
|
||||
|
||||
":dependsOnPlainJvm:compileTestKotlinJvm",
|
||||
":dependsOnPlainJvm:compileTestJava",
|
||||
":dependsOnJvmWithJava:compileTestKotlinJvm",
|
||||
":dependsOnJvmWithJava:compileTestJava",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun publishThirdPartyLib(
|
||||
projectName: String = "third-party-lib".withPrefix,
|
||||
withGranularMetadata: Boolean,
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
kotlin("multiplatform").apply(false)
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
val disambiguationAttribute = Attribute.of("disambiguationAttribute", String::class.java)
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
withJava()
|
||||
attributes { attribute(disambiguationAttribute, "jvmWithJava") }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
api(project(":lib"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package test;
|
||||
|
||||
public class MainJava {
|
||||
public static void main() {
|
||||
JvmWithJava obj1 = new JvmWithJava();
|
||||
JvmWithJavaKotlin obj2 = new JvmWithJavaKotlin();
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
fun main() {
|
||||
val kotlin = JvmWithJavaKotlin()
|
||||
val java = JvmWithJava()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package test;
|
||||
|
||||
public class MainJavaTest {
|
||||
public static void main() {
|
||||
JvmWithJava obj1 = new JvmWithJava();
|
||||
JvmWithJavaKotlin obj2 = new JvmWithJavaKotlin();
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
fun main() {
|
||||
val kotlin = JvmWithJavaKotlin()
|
||||
val java = JvmWithJava()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
val disambiguationAttribute = Attribute.of("disambiguationAttribute", String::class.java)
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
withJava()
|
||||
attributes { attribute(disambiguationAttribute, "plainJvm") }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
api(project(":lib"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
public class MainJava {
|
||||
public static void main() {
|
||||
PlainJvmKotlin obj = new PlainJvmKotlin();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun main() {
|
||||
val kotlin = PlainJvmKotlin()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
public class MainJavaTest {
|
||||
public static void main() {
|
||||
PlainJvmKotlin obj = new PlainJvmKotlin();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun main() {
|
||||
val kotlin = PlainJvmKotlin()
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
val disambiguationAttribute = Attribute.of("disambiguationAttribute", String::class.java)
|
||||
|
||||
kotlin {
|
||||
jvm("plainJvm") {
|
||||
attributes { attribute(disambiguationAttribute, "plainJvm") }
|
||||
}
|
||||
|
||||
jvm("jvmWithJava") {
|
||||
withJava()
|
||||
attributes { attribute(disambiguationAttribute, "jvmWithJava") }
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test;
|
||||
|
||||
public class JvmWithJava {
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
class JvmWithJavaKotlin {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
class PlainJvmKotlin {
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
include("lib", "dependsOnPlainJvm", "dependsOnJvmWithJava")
|
||||
+75
@@ -218,4 +218,79 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test that jvm target attributes are propagated to java configurations`() {
|
||||
val disambiguationAttribute = org.gradle.api.attributes.Attribute.of("disambiguationAttribute", String::class.java)
|
||||
val project = buildProjectWithMPP {
|
||||
|
||||
kotlin {
|
||||
jvm("plainJvm") {
|
||||
attributes { attribute(disambiguationAttribute, "plainJvm") }
|
||||
}
|
||||
|
||||
jvm("jvmWithJava") {
|
||||
withJava()
|
||||
attributes { attribute(disambiguationAttribute, "jvmWithJava") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//NB: There is no "api" configuration registered by Java Plugin
|
||||
val javaConfigurations = listOf(
|
||||
"compileClasspath",
|
||||
"runtimeClasspath",
|
||||
"implementation",
|
||||
"compileOnly",
|
||||
"runtimeOnly"
|
||||
)
|
||||
|
||||
val kotlinJvmConfigurations = listOf(
|
||||
"jvmWithJavaCompileClasspath",
|
||||
"jvmWithJavaRuntimeClasspath",
|
||||
"jvmWithJavaApi",
|
||||
"jvmWithJavaImplementation",
|
||||
"jvmWithJavaCompileOnly",
|
||||
"jvmWithJavaRuntimeOnly",
|
||||
)
|
||||
|
||||
val outgoingConfigurations = listOf(
|
||||
"jvmWithJavaApiElements",
|
||||
"jvmWithJavaRuntimeElements",
|
||||
)
|
||||
|
||||
val testJavaConfigurations = listOf(
|
||||
"testCompileClasspath",
|
||||
"testCompileOnly",
|
||||
"testImplementation",
|
||||
"testRuntimeClasspath",
|
||||
"testRuntimeOnly"
|
||||
)
|
||||
|
||||
val jvmWithJavaTestConfigurations = listOf(
|
||||
"jvmWithJavaTestCompileClasspath",
|
||||
"jvmWithJavaTestRuntimeClasspath",
|
||||
"jvmWithJavaTestApi",
|
||||
"jvmWithJavaTestCompileOnly",
|
||||
"jvmWithJavaTestImplementation",
|
||||
"jvmWithJavaTestRuntimeOnly"
|
||||
)
|
||||
|
||||
val expectedConfigurationsWithDisambiguationAttribute = javaConfigurations +
|
||||
kotlinJvmConfigurations +
|
||||
outgoingConfigurations +
|
||||
testJavaConfigurations +
|
||||
jvmWithJavaTestConfigurations
|
||||
|
||||
with(project.evaluate()) {
|
||||
val actualConfigurationsWithDisambiguationAttribute = configurations
|
||||
.filter { it.attributes.getAttribute(disambiguationAttribute) == "jvmWithJava" }
|
||||
.map { it.name }
|
||||
|
||||
assertEquals(
|
||||
expectedConfigurationsWithDisambiguationAttribute.sorted(),
|
||||
actualConfigurationsWithDisambiguationAttribute.sorted()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user