karakum-team / karakum

Converter of TypeScript declaration files to Kotlin declarations
Apache License 2.0
37 stars 0 forks source link

Extension of type 'KotlinMultiplatformExtension' does not exist #2

Closed joffrey-bion closed 1 year ago

joffrey-bion commented 1 year ago

It seems that the Karakum Gradle plugin assumes the Kotlin multiplatform plugin is applied. In my project where I apply kotlin("js"), I'm getting the following:

org.gradle.api.UnknownDomainObjectException: Extension of type 'KotlinMultiplatformExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, LibrariesForLibs, VersionCatalogsExtension, KotlinJsProjectExtension, KotlinTestsRegistry, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, PublishingExtension, GithubInfoExtension, SigningExtension]
        at org.gradle.internal.extensibility.ExtensionsStorage.getHolderByType(ExtensionsStorage.java:88)
        at org.gradle.internal.extensibility.ExtensionsStorage.getByType(ExtensionsStorage.java:74)
        at org.gradle.internal.extensibility.DefaultConvention.getByType(DefaultConvention.java:160)
        at io.github.sgrishchenko.karakum.gradle.plugin.tasks.TasksKt.getKotlinJsCompilation(Tasks.kt:26)
        at io.github.sgrishchenko.karakum.gradle.plugin.tasks.KarakumGenerate.<init>(KarakumGenerate.kt:29)
        at io.github.sgrishchenko.karakum.gradle.plugin.tasks.KarakumGenerate_Decorated.<init>(Unknown Source)
        ...

This is due to this line: https://github.com/karakum-team/karakum/blob/master/gradle-plugin/karakum-gradle-plugin/src/main/kotlin/io/github/sgrishchenko/karakum/gradle/plugin/tasks/Tasks.kt#L14

I think it should be modified to get the Kotlin JS compilation from either the MPP plugin or the K/JS plugin depending on which one is present.

Also, note that this is called during the constructor of the KarakumGenerate task, which might cause problems with plugin application ordering (this forces users to apply the Kotlin MPP plugin before the Karakum plugin). It would be best to configure the Karakum plugin using conventions and plugin application "reaction" blocks like withPlugin.

turansky commented 1 year ago

Current plan - support multiplatform plugin only. Please use multiplatform plugin instead of js.

joffrey-bion commented 1 year ago

I don't understand. This project is meant to help with Kotlin wrapper projects for Kotlin JS. Why focus on the multiplatform plugin if the main consumers are js-only projects?

Do you mean that as a general rule we should prefer using the Kotlin Multiplatform Gradle plugin over the Kotlin JS Gradle plugin, even for projects that only target the JS platform?

joffrey-bion commented 1 year ago

Got my answer here: https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#migration-from-kotlin-js-gradle-plugin-to-kotlin-multiplatform-gradle-plugin

So yes, we're supposed to use the kotlin-multiplatform plugin only now.