JetBrains / intellij-platform-gradle-plugin

Gradle plugin for building plugins for IntelliJ-based IDEs
https://plugins.jetbrains.com/docs/intellij/gradle-prerequisites.html
Apache License 2.0
1.43k stars 271 forks source link

does not work together with kotlin-multiplatform #1507

Open Zane-XY opened 10 months ago

Zane-XY commented 10 months ago

What happened?

The plugin project may include shared subproject modules that target Kotlin Multiplatform. However, when the plugin subproject uses the Kotlin JVM plugin, it is unable to resolve the project(":shared-subproject") dependency correctly. On the other hand, if the plugin subproject uses the Kotlin Multiplatform plugin, it can resolve the shared project dependency. But, it may not recognize the SDK dependency brought by the IntelliJ plugin and fails to compile. Need to confirm if it is possible to achieve a shared subject compiles to multiplatform targets in an IntelliJ plugin project?

Relevant log output or stack trace

No response

Steps to reproduce

as above description.

Gradle IntelliJ Plugin version

1.16.1

Gradle version

8.5

Operating System

None

Link to build, i.e. failing GitHub Action job

No response

hsz commented 9 months ago

Please provide a minimal reproducible example so I could review your issue locally.

ZacSweers commented 7 months ago

@hsz here is a reproducer: https://github.com/slackhq/slack-gradle-plugin/tree/main/skate-plugin

The plugin appears to be missing compiled kotlin deps, seemingly because it does not find the correct KotlinCompile task in multiplatform

I see the following task dependency tree in multiplatform

:skate-plugin:initializeIntelliJPlugin SKIPPED
:skate-plugin:generateBuildConfig SKIPPED
:skate-plugin:patchPluginXml SKIPPED
:skate-plugin:verifyPluginConfiguration SKIPPED
:skate-plugin:compileJava SKIPPED
:skate-plugin:processResources SKIPPED
:skate-plugin:classes SKIPPED
:skate-plugin:instrumentCode SKIPPED
:skate-plugin:classpathIndexCleanup SKIPPED
:skate-plugin:instrumentedJar SKIPPED
:skate-plugin:jar SKIPPED
:skate-plugin:prepareSandbox SKIPPED
:skate-plugin:buildSearchableOptions SKIPPED
:skate-plugin:jarSearchableOptions SKIPPED
:skate-plugin:buildPlugin SKIPPED

missing the compileKotlinJvm task that the kotlin multiplatform uses for the jvmMain source set instead. This seems to be due to it exclusively looking for compileKotlin here: https://github.com/JetBrains/intellij-platform-gradle-plugin/blob/bb484a6824455fe5df5cec2fb756bbb3a03b7cb4/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt#L140

ZacSweers commented 7 months ago

It also appears to only look for the kotlin jvm plugin: https://github.com/JetBrains/intellij-platform-gradle-plugin/blob/bb484a6824455fe5df5cec2fb756bbb3a03b7cb4/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt#L41

hsz commented 7 months ago

Thanks, Zac! I'll check it soon, but most likely any possible fix will be provided with the 2.0 release.

ZacSweers commented 7 months ago

I think the issue is actually from depending on the wrong Jar task, as there is a separate jarJvm task from the standard jar task that the plugin looks for. I'm looking into it and seeing if I can put together a PR 👍. In the meantime, the property using a convention means it should be possible to workaround this without a new release. I'll update here when I have more details

hsz commented 3 months ago

I just managed to change the default jar task to jarJvm but there's more work required here, as kotlin.jvm in KMP doesn't work on default set but custom subset of dependencies, configurations, sourceSets, and tasks. In 2.x the support for KMP could be possible, but this needs to be investigated at first.