[gradle-plugin] Publish Kotlin metadata variant
Fix for KT-27500.
This commit is contained in:
committed by
Ilya Matveev
parent
e5ab2c71fb
commit
f68f7028b1
+13
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.gradle.api.component.ComponentWithVariants
|
||||
import org.gradle.api.component.SoftwareComponent
|
||||
import org.gradle.api.internal.component.SoftwareComponentInternal
|
||||
@@ -30,8 +31,11 @@ import org.gradle.internal.DisplayName
|
||||
import org.gradle.language.ProductionComponent
|
||||
import org.gradle.language.cpp.internal.NativeVariantIdentity
|
||||
import org.gradle.language.nativeplatform.internal.PublicationAwareComponent
|
||||
import org.jetbrains.kotlin.gradle.plugin.EXPECTED_BY_CONFIG_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSetImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNativeMainComponent @Inject constructor(
|
||||
@@ -50,6 +54,13 @@ open class KotlinNativeMainComponent @Inject constructor(
|
||||
set(mutableSetOf(OutputKind.KLIBRARY))
|
||||
}
|
||||
|
||||
private val metadataDependencies = project.configurations.create(names.withPrefix("metadata")).apply {
|
||||
isCanBeConsumed = false
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, KotlinUsages.KOTLIN_API))
|
||||
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
|
||||
extendsFrom(getImplementationDependencies())
|
||||
}
|
||||
|
||||
private val mainPublication = KotlinNativeVariant()
|
||||
|
||||
override fun getMainPublication(): KotlinNativeVariant = mainPublication
|
||||
@@ -89,8 +100,8 @@ open class KotlinNativeMainComponent @Inject constructor(
|
||||
|
||||
override fun getName(): String = this@KotlinNativeMainComponent.name
|
||||
|
||||
override fun getUsages(): Set<UsageContext> = emptySet()
|
||||
|
||||
override fun getUsages(): Set<UsageContext> =
|
||||
setOf(MetadataUsageContext("metadata-api", project.objects, metadataDependencies))
|
||||
}
|
||||
// endregion
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
||||
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.artifacts.*
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.gradle.api.capabilities.Capability
|
||||
import org.gradle.api.internal.component.UsageContext
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
|
||||
class MetadataUsageContext(
|
||||
private val _name: String,
|
||||
val objects: ObjectFactory,
|
||||
val configuration: Configuration
|
||||
): UsageContext, Named {
|
||||
|
||||
override fun getUsage(): Usage = objects.named(Usage::class.java, KotlinUsages.KOTLIN_API)
|
||||
override fun getName(): String = _name
|
||||
|
||||
override fun getCapabilities(): Set<Capability> = emptySet()
|
||||
override fun getGlobalExcludes(): Set<ExcludeRule> = emptySet()
|
||||
|
||||
override fun getDependencies(): Set<out ModuleDependency> =
|
||||
configuration.incoming.dependencies.withType(ModuleDependency::class.java)
|
||||
|
||||
override fun getDependencyConstraints(): MutableSet<out DependencyConstraint> =
|
||||
configuration.incoming.dependencyConstraints
|
||||
|
||||
override fun getArtifacts(): MutableSet<out PublishArtifact> =
|
||||
configuration.outgoing.artifacts
|
||||
|
||||
override fun getAttributes(): AttributeContainer =
|
||||
configuration.outgoing.attributes
|
||||
}
|
||||
@@ -900,7 +900,7 @@ class ExperimentalPluginTests {
|
||||
version '1.0'
|
||||
|
||||
sourceSets.main.component {
|
||||
targets = ['wasm32']
|
||||
targets = ['wasm32', 'host']
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -935,10 +935,6 @@ class ExperimentalPluginTests {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
wasmMain {
|
||||
dependencies {
|
||||
implementation 'test:native-producer:1.0'
|
||||
}
|
||||
}
|
||||
@@ -974,8 +970,12 @@ class ExperimentalPluginTests {
|
||||
buildFile.writeText("""
|
||||
plugins {
|
||||
id 'kotlin-native'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
group 'test'
|
||||
version '1.0'
|
||||
|
||||
repositories {
|
||||
maven { url '$repoPath' }
|
||||
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
|
||||
@@ -989,20 +989,72 @@ class ExperimentalPluginTests {
|
||||
dependencies {
|
||||
implementation 'test:mpp:1.0'
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven { url = '$repoPath' }
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
settingsFile.appendText("enableFeaturePreview('GRADLE_METADATA')")
|
||||
generateSrcFile("consumer.kt", "fun consumer() = mpp()")
|
||||
}
|
||||
|
||||
val mppConsumer = KonanProject.createEmpty(tmpFolder.newFolder("mpp-consumer")).apply {
|
||||
buildFile.writeText("""
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.multiplatform' version '${MultiplatformSpecification.KOTLIN_VERSION}'
|
||||
}
|
||||
|
||||
group 'test'
|
||||
version '1.0'
|
||||
|
||||
repositories {
|
||||
maven { url '$repoPath' }
|
||||
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
|
||||
jcenter()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
implementation 'test:native-consumer:1.0'
|
||||
}
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(presets.wasm32, 'wasm')
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
settingsFile.writeText("""
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
enableFeaturePreview('GRADLE_METADATA')
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
nativeProducer.createRunner().withArguments("publish").build()
|
||||
mpp.createRunner().withArguments("publish").build()
|
||||
nativeConsumer.createRunner().withArguments("build").build()
|
||||
mpp.createRunner().withArguments("dependencies").build().also {
|
||||
assertFalse(it.output.contains("FAILED"))
|
||||
}
|
||||
nativeConsumer.createRunner().withArguments("publish").build()
|
||||
mppConsumer.createRunner().withArguments("dependencies").build().also {
|
||||
assertFalse(it.output.contains("FAILED"))
|
||||
}
|
||||
|
||||
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/native-producer_debug_wasm32/1.0/native-producer_debug_wasm32-1.0.module",
|
||||
"repo/test/native-producer_debug_wasm32/1.0/native-producer_debug_wasm32-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"
|
||||
|
||||
Reference in New Issue
Block a user