Add Kotlin-specific Usage attribute values
When a non-Kotlin (JVM) project resolves an MPP library dependency,
it expects only one variant per Java Usage value ('java-api',
'java-runtime-jars'). If there's more than one, it will report
ambiguity and fail.
So we need to avoid creating non-JVM variants with Java Usage values
to ensure that non-Kotlin consumers can resolve the dependencies on
an MPP library with a single JVM target (if there's more than one
JVM target, there will still be ambiguity, but that's quite what one
would expect and what can be solved with custom attributes).
Instead, we define two Kotlin-specific Usage values, 'kotlin-api' and
'kotlin-runtime', so that:
* input configurations with these Usage values can consume plain Java
artifacts, for compatibility with plain old Kotlin modules
* if a consumer does not request a Kotlin usage and receives the two,
let it use the runtime one as it is more complete
We then use the two Usage values on those Kotlin input and output
configurations which are not JVM-related, and leave the Java Usages
for the JVM targets.
This commit is contained in:
+19
@@ -584,6 +584,25 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConsumeMppLibraryFromNonKotlinProject() {
|
||||
val libRepo = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
build("publish") { assertSuccessful() }
|
||||
projectDir.resolve("repo")
|
||||
}
|
||||
|
||||
with(Project("sample-app-without-kotlin", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().appendText("\nrepositories { maven { url '${libRepo.toURI()}' } }")
|
||||
|
||||
build("assemble") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":compileJava")
|
||||
assertFileExists("build/classes/java/main/A.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNativeTests() = with(Project("new-mpp-native-tests", gradleVersion)) {
|
||||
val testTasks = listOf("macos64Test", "linux64Test", "mingw64Test")
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.example:sample-lib:1.0'
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
enableFeaturePreview('GRADLE_METADATA')
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import com.example.lib.CommonKt;
|
||||
|
||||
public class A {
|
||||
public void useKotlinClass() {
|
||||
CommonKt.id(123);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user