When using `org.jetbrains.kotlin.multiplatform` , ...
# gradle
m
When using
org.jetbrains.kotlin.multiplatform
, can I add variants to the "main" publication? In JVM world, I can do this:
Copy code
val outgoingConfiguration = configurations.consumable("myOutgoingConfiguration") {
  attributes {
    attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>("myUsage"))
  }
}.get()

artifacts {
  add(outgoingConfiguration.name, myArtifact)
}

// How do I do this in KMP?
(components.get("java") as AdhocComponentWithVariants).addVariantsFromConfiguration(outgoingConfiguration) {}
Is there a KMP equivalent?
t
cc @Anton Lakotka [JB]
a
https://youtrack.jetbrains.com/issue/KT-58830/Expose-AdhocComponentWithVariants-API-on-KGP-generated-component please upvote this. And could you please provide your usecase? I might add some simple API under "experimental opt-in" (so no backward compatible guarantees) to add extra variants to outgouing publications.
1
m
Upvoted!
Use case to publish GraphQL metadata alongside the bytecode. We're now using a separate publication but it breaks on transitive usages, see this slack thread
thank you color 1
a
I'll try to reach you back with more updates on this.
m
Thanks!
a
Shame on us that you had to write this code
😅 3
m
Thanks @CLOVIS 🙏
Somewhat related question, can I get the
rootSoftwareComponent
without reflection?
For targets, I can do
kotlin.targets.getByName("jvm").components
but the root component doesn't have a target or does it?
a
I'm not sure, but you can try asking MetadataTarget. But perhaps it is not there either. Idon't remember from top of my head
m
The "metadata" target has an empty list of components
I can do a bit more reflection, this is fine at this point 🙂 . If you end up adding APIs, would be cool to add the root component as well (if not there already)
👌 1
a
I also vote for this feature request. In my case, I want to publish a multiplatform WASM binary in the root (common) target so that it is accessible from all other targets. Currently, for the common target, the best solution I have found is to create my own rootSoftwareComponent, add my artifact to it, and copy the root KotlinMultiplatform publication with this component: https://github.com/illarionov/wasm-sqlite-driver-binary/blob/85e9d8729b550ec7fc57360841ce61b7aedcebfd/build-logic/project/multiplatform/src/main/kotlin/wasm-resources.gradle.kts#L55
m
Damn, the root component is different. It's a
KotlinSoftwareComponentWithCoordinatesAndPublication
, not a
KotlinTargetSoftwareComponent
, no adhocComponent ther
😻