Error building jar for kotlin in IntelliJ for desktop

Answered

I'm trying to build an executable jar file for the a demo desktop compose project with IntelliJ IDEA 2023.3.4 (Community Edition). The kotlin project is the "hello word" that intelliJ creates by default. When I follow all the steps to build the jar file , I receive this error:

Kotlin: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar is not compatible with this version of compiler. 

I'm using the following versions for Kotlin Compiler and compose compiler:

plugins { kotlin("jvm").version("1.9.22") 

id("org.jetbrains.compose").version("1.5.12") }

I've tried to force the compose compiler 1.5.8 that is the compatible with 1.5.12 compose , but it doesn't work:

compose { kotlinCompilerPlugin.set("1.5.8") }

I've installed the Compose Multiplatform IDE support Plugin 1.5.12 Target JVM is 1.8. 

Gradle JVM is JDK-21 version 21.0.2

I'd like to know how to proceed to succesfully compile my jar file.

0
14 comments
Hello Jjsanma1, 

Can you please provide the project with the issue reproduction? 
And can you please clarify how do you create the Compose project?
And how do you trigger the issue?

Thank you!
0
Unfortunately I unable to reproduce the issue even with your project (build is completed successfully, jar file generated successfully). 
Can you please provide step-by-step scenario of the issue reproduction and a video of the issue reproduction? 
Thank you in advance!

P.S. The versions of Kotlin Plugin and compose plugin differs from that you mentioned in a newly created project in IDEA 2023.3.4.
0

https://drive.google.com/drive/folders/15cuURJC2vtQiaPu9NbSkmMYvO9mdstO3?usp=sharing

I attach a video with the procedure to replicate the issue. I've used the demo hello word application. I've updated the demo.zip to reflect the versions I've used in my question (kotlin V1.9.22).

0
I understand the reproduction: It is necessary to select menu Build -> Groovy Resources -> Build Resources.

Kotlin: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar is not compatible with this version of compiler.
java.lang.AbstractMethodError: Receiver class androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar does not define or inherit an implementation of the resolved method 'abstract void registerProjectComponents(com.intellij.mock.MockProject, org.jetbrains.kotlin.config.CompilerConfiguration)' of interface org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar.
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli_base(KotlinCoreEnvironment.kt:689)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:164)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.configureProjectEnvironment(KotlinCoreEnvironment.kt:587)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.(KotlinCoreEnvironment.kt:194)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.(KotlinCoreEnvironment.kt)
0
As I see the same stack trace is mentioned here: KTIJ-28778 (https://youtrack.jetbrains.com/issue/KTIJ-28778/Kotlin-Multiplatform-Wizard-issue-Build-Artifacts-composeApp-Desktop-Fails)
Please follow the news in the tickets. In addition you can also participate in the discussion of the issue. 
 
Can you please also check the build -> libs folder. Is there a JAR file generated after a build of the application?

Thank you!
0

Thanks , yes I'm following the trace you mention but no solution so far.

Regarding your question about build → libs folder : 

when I run the application (it builds the code before) a jar file called demo-1.0-SNAPSHOT.jar  appears in the build/libs. folder .

if I just build the application , no jar file appears. 

if I build artifacts , no jar file appears. 

 

Regards

0
I assume you try to run the Build command via IDEA menu.
Try to build the project via ./gradlew build commmand and look how it goes. 

If you want to use IDEA menu, then you need to follow this instuction: https://www.jetbrains.com/help/idea/working-with-artifacts.html

Thank you!
0

Yes I use Idea Menu . If I try to use ./gradlew build commmand , I get an error like :  error running ./gradlew build commmand . can not run program ./gradlew build commmand in directory c:\…..    create process error=2.

On the other hand the instuction you propose : https://www.jetbrains.com/help/idea/working-with-artifacts.html is the one I am using from the begining , and I get the error I reported in my first trace : Kotlin: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar is not compatible with this version of compiler.

 

0
Try to use just run gradle build command.
You also can open Gradle section in project in IDEA, click Execute Gradle Task, then try to execute gradle or ./gradlew commands from there.  

Regarding the instruction https://www.jetbrains.com/help/idea/working-with-artifacts.html: 
Indeed when you just create a project and try to build artifacts, then I receive the initially reported issue.
But if follow the instruction (Go to Project Structure - Artifacts - Add JAR - empty - create Manifest, then if try to use IDEA Build menu - Build artifacts, then the jar file appeared in the 'out' folder in the project. 
Better to use Gradle commands for building arficacts in general. If you use IDEA menu, then IDEA tries to build it, not Gradle.
0

Following instruction you mention : "Go to Project Structure - Artifacts - Add JAR - empty - create Manifest", the jar created doesn't include the complete project . To include the complete project you have to select Go to Project Structure - Artifacts - Add JAR - from modules with dependencies. But in this case , when I try to compile the artifact , I receive the original error regardless of the method I follow : both Idea menu or gradle commands. 

If you succeed compiling the artifact including the complete project , could you please send a video? 

Regards

 

0
You can try to use a workaround from this ticket: https://youtrack.jetbrains.com/issue/KT-66494, but in this case you need to use the whole string line for the jar file. 
Or use package gradle tasks to generate an executable file of the app.
It looks we need to wait for the fix in KTIJ-28778. Unfortunately I do not see other workarounds for the issue.
0

I finally succeed by using the command  “./gradlew packageUberJarForCurrentOS” . 

It creates a jar than you can execute through JRE in my windows OS machine. Thanks

0

Please sign in to leave a comment.