CLOVIS
12/04/2023, 8:37 PMkotlin("multiplatform") plugin to a build. When running ./gradlew :components , I get:
No components defined for this project.
Note: currently not all plugins register their components, so some components may not be visible here.
Is this planned? Is there a reason in particular this cannot be done?
I would like to add a new variant to the Kotlin Multiplatform artifacts, by having it be mentioned in the Gradle Module Metadata for the Multiplatform publication. Is there another way to add information to it?Jeff Lockhart
12/04/2023, 10:24 PMAdhocComponentWithVariants reference via reflection. It would be nice if my PR got a look to open up the API directly.mbonnin
12/04/2023, 10:53 PMCLOVIS
12/05/2023, 8:55 AMCLOVIS
12/05/2023, 8:55 AMCLOVIS
12/06/2023, 7:56 PMKotlinTargetComponent s, but these don't seem to implement AdhocComponentWithVariants , so how I can add my own variants to them?Jeff Lockhart
12/07/2023, 7:59 PMAdhocComponentWithVariants reference should be accessible alongside the KotlinTargetComponent reference if you can go up another level to the KotlinTargetSoftwareComponent object.
And it appears you can get the KotlinTargetSoftwareComponent reference from the KotlinTarget.components property, rather than KotlinTarget.kotlinComponents in @mbonnin’s reflection method, which looks to be accessible without reflection, but possibly requiring an opt-in. You might try casting to KotlinTargetSoftwareComponentImpl and accessing adhocComponent via reflection.CLOVIS
12/09/2023, 11:53 AMKotlinTargetSoftwareComponent instance following what you said, but I'm not sure how to access the AdhocComponentWithVariants from that.
Using component::class.members.find { it.name == "adhocComponent" } , I do get access to the field, however if I try to call it I get:
class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetSoftwareComponentImpl with modifiers "private final"
Since it's a private field, no getter is generated, so I cannot use Java reflection with setAccessible(true) . Is there another way to access the field?Jeff Lockhart
12/09/2023, 6:27 PMsetAccessible(true) on a field reference. Try:
val adHocField = Class.forName("org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetSoftwareComponentImpl")
.declaredFields.find { it.type == AdhocComponentWithVariants::class.java }
adHocField?.isAccessible = trueCLOVIS
12/09/2023, 8:59 PM--------------------------------------------------
Variant exposedKotlinJsResources
--------------------------------------------------
Capabilities
- example-kmp:core:unspecified (default capability)
Attributes
- dev.opensavvy.resources = Regular
- org.gradle.category = library
- org.gradle.libraryelements = resources
Artifacts
- build/distributions/core-kjs-assets.zip (artifactType = zip, classifier = kjs-assets)
However, it doesn't appear in the .module files when calling ./gradlew publishToMavenLocal 😕CLOVIS
12/09/2023, 9:07 PMafterEvaluate , it now works 🙂CLOVIS
12/09/2023, 9:08 PM