Use KOTLIN_API usage instead of JAVA_API (#2231)
* [gradle-plugin] Use KOTLIN_API usage instead of JAVA_API * [gradle-plugin] Add a test for compatibility with the mpp plugin
This commit is contained in:
+2
-1
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.gradle.plugin.experimental.ComponentWithBaseName
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ abstract class AbstractKotlinNativeBinary(
|
|||||||
// A configuration containing klibs.
|
// A configuration containing klibs.
|
||||||
override val klibs = configurations.create(names.withPrefix("klibs")).apply {
|
override val klibs = configurations.create(names.withPrefix("klibs")).apply {
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_API))
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, KotlinUsages.KOTLIN_API))
|
||||||
attributes.attribute(CppBinary.DEBUGGABLE_ATTRIBUTE, debuggable)
|
attributes.attribute(CppBinary.DEBUGGABLE_ATTRIBUTE, debuggable)
|
||||||
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, optimized)
|
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, optimized)
|
||||||
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
|
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
|
||||||
|
|||||||
+8
-5
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
||||||
|
|
||||||
import org.gradle.api.attributes.*
|
import org.gradle.api.attributes.*
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
|
|
||||||
open class Compatible: AttributeCompatibilityRule<Boolean> {
|
open class Compatible: AttributeCompatibilityRule<Boolean> {
|
||||||
override fun execute(details: CompatibilityCheckDetails<Boolean>) = details.compatible()
|
override fun execute(details: CompatibilityCheckDetails<Boolean>) = details.compatible()
|
||||||
@@ -44,17 +45,19 @@ open class UsageCompatibility: AttributeCompatibilityRule<Usage> {
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
requested == null -> compatible()
|
requested == null -> compatible()
|
||||||
requested == Usage.JAVA_API && (provided == Usage.JAVA_API || provided == KotlinNativeUsage.KLIB) -> {
|
requested in supportedRequestedUsages && provided in supportedProvidedUsages -> compatible()
|
||||||
compatible()
|
|
||||||
}
|
|
||||||
requested == provided -> compatible()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val supportedRequestedUsages = listOf(KotlinUsages.KOTLIN_API, Usage.JAVA_API)
|
||||||
|
val supportedProvidedUsages = listOf(KotlinUsages.KOTLIN_API, Usage.JAVA_API, KotlinNativeUsage.KLIB)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class UsageDisambiguation: AttributeDisambiguationRule<Usage> {
|
open class UsageDisambiguation: AttributeDisambiguationRule<Usage> {
|
||||||
override fun execute(details: MultipleCandidatesDetails<Usage>): Unit = with(details) {
|
override fun execute(details: MultipleCandidatesDetails<Usage>): Unit = with(details) {
|
||||||
val usagePriority = listOf(Usage.JAVA_API, KotlinNativeUsage.KLIB)
|
val usagePriority = listOf(KotlinUsages.KOTLIN_API, Usage.JAVA_API, KotlinNativeUsage.KLIB)
|
||||||
usagePriority.forEach { usage ->
|
usagePriority.forEach { usage ->
|
||||||
val found = candidateValues.find { it.name == usage }
|
val found = candidateValues.find { it.name == usage }
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
|
|||||||
+3
-4
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
|||||||
|
|
||||||
import org.gradle.api.attributes.Usage
|
import org.gradle.api.attributes.Usage
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.konan.target.Family
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
@@ -42,9 +43,7 @@ enum class OutputKind(
|
|||||||
KotlinNativeLibraryImpl::class.java,
|
KotlinNativeLibraryImpl::class.java,
|
||||||
1,
|
1,
|
||||||
null,
|
null,
|
||||||
// Use JAVA_API here because the MPP plugin uses this usage for all artifacts in 1.3-RC.
|
KotlinUsages.KOTLIN_API
|
||||||
// TODO: Change to KOTLIN_API with such change is merged into big Kotlin's 1.3.
|
|
||||||
Usage.JAVA_API
|
|
||||||
),
|
),
|
||||||
FRAMEWORK(
|
FRAMEWORK(
|
||||||
CompilerOutputKind.FRAMEWORK,
|
CompilerOutputKind.FRAMEWORK,
|
||||||
@@ -63,7 +62,7 @@ enum class OutputKind(
|
|||||||
3,
|
3,
|
||||||
Usage.NATIVE_RUNTIME,
|
Usage.NATIVE_RUNTIME,
|
||||||
Usage.NATIVE_LINK,
|
Usage.NATIVE_LINK,
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
override fun availableFor(target: KonanTarget): Boolean = target != KonanTarget.WASM32
|
override fun availableFor(target: KonanTarget): Boolean = target != KonanTarget.WASM32
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.gradle.plugin.experimental.CInteropSettings.IncludeD
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeBuildType
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeBuildType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.getGradleOSFamily
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.getGradleOSFamily
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -81,7 +82,7 @@ open class CInteropSettingsImpl @Inject constructor(
|
|||||||
val objects = project.objects
|
val objects = project.objects
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
isCanBeResolved = true
|
isCanBeResolved = true
|
||||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_API))
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, KotlinUsages.KOTLIN_API))
|
||||||
attributes.attribute(CppBinary.DEBUGGABLE_ATTRIBUTE, KotlinNativeBuildType.DEBUG.debuggable)
|
attributes.attribute(CppBinary.DEBUGGABLE_ATTRIBUTE, KotlinNativeBuildType.DEBUG.debuggable)
|
||||||
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, KotlinNativeBuildType.DEBUG.optimized)
|
attributes.attribute(CppBinary.OPTIMIZED_ATTRIBUTE, KotlinNativeBuildType.DEBUG.optimized)
|
||||||
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
|
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
|
||||||
|
|||||||
@@ -884,4 +884,125 @@ class ExperimentalPluginTests {
|
|||||||
}
|
}
|
||||||
project.createRunner().withArguments("assertClassPath").build()
|
project.createRunner().withArguments("assertClassPath").build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Plugin should be compatible with the MPP one`() {
|
||||||
|
val repo = tmpFolder.newFolder("repo")
|
||||||
|
val repoPath = KonanProject.escapeBackSlashes(repo.absolutePath)
|
||||||
|
val nativeProducer = KonanProject.createEmpty(tmpFolder.newFolder("native-producer")).apply {
|
||||||
|
buildFile.writeText("""
|
||||||
|
plugins {
|
||||||
|
id 'kotlin-native'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'test'
|
||||||
|
version '1.0'
|
||||||
|
|
||||||
|
sourceSets.main.component {
|
||||||
|
targets = ['wasm32']
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = '$repoPath' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
settingsFile.appendText("enableFeaturePreview('GRADLE_METADATA')")
|
||||||
|
generateSrcFile("native.kt", "fun native() = 42")
|
||||||
|
}
|
||||||
|
|
||||||
|
val mpp = KonanProject.createEmpty(tmpFolder.newFolder("mpp")).apply {
|
||||||
|
buildFile.writeText("""
|
||||||
|
plugins {
|
||||||
|
id 'org.jetbrains.kotlin.multiplatform' version '${MultiplatformSpecification.KOTLIN_VERSION}'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'test'
|
||||||
|
version '1.0'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url '$repoPath' }
|
||||||
|
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
wasmMain {
|
||||||
|
dependencies {
|
||||||
|
implementation 'test:native-producer:1.0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targets {
|
||||||
|
fromPreset(presets.wasm32, 'wasm')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = '$repoPath' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
settingsFile.writeText("""
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enableFeaturePreview('GRADLE_METADATA')
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
propertiesFile.writeText("org.jetbrains.kotlin.native.home=$konanHome")
|
||||||
|
generateSrcFile(listOf("src/wasmMain/kotlin"), "mpp.kt", "fun mpp() = native()")
|
||||||
|
}
|
||||||
|
|
||||||
|
val nativeConsumer = KonanProject.createEmpty(tmpFolder.newFolder("native-consumer")).apply {
|
||||||
|
buildFile.writeText("""
|
||||||
|
plugins {
|
||||||
|
id 'kotlin-native'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url '$repoPath' }
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.main.component {
|
||||||
|
targets = ['wasm32']
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'test:mpp:1.0'
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
settingsFile.appendText("enableFeaturePreview('GRADLE_METADATA')")
|
||||||
|
generateSrcFile("consumer.kt", "fun consumer() = mpp()")
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeProducer.createRunner().withArguments("publish").build()
|
||||||
|
mpp.createRunner().withArguments("publish").build()
|
||||||
|
nativeConsumer.createRunner().withArguments("build").build()
|
||||||
|
|
||||||
|
val publishedFiles = listOf(
|
||||||
|
"repo/test/native-producer/1.0/native-producer-1.0.module",
|
||||||
|
"repo/test/native-producer_debug/1.0/native-producer_debug-1.0.module",
|
||||||
|
"repo/test/native-producer_debug/1.0/native-producer_debug-1.0.klib",
|
||||||
|
"repo/test/mpp/1.0/mpp-1.0.module",
|
||||||
|
"repo/test/mpp-wasm/1.0/mpp-wasm-1.0.module",
|
||||||
|
"repo/test/mpp-wasm/1.0/mpp-wasm-1.0.klib"
|
||||||
|
)
|
||||||
|
|
||||||
|
publishedFiles.forEach {
|
||||||
|
assertFileExists(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user