Kotlin jetpack compose desktop in Jar does not work

I have a project on Koltin, I’m using the compose desktop template in intellij idea, I’m trying to compile it into a Jar via Artifacts by selecting jar → form modules with dependencies . In the Bild tab, select bild artifacts and click bild under the file.

An error appears in the console

Kotlin: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar is not compatible with this version of compiler.
java.lang.AbstractMethodError: Receiver class androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar 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(KotlinCoreEnvironment.kt:671)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:162)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.configureProjectEnvironment(KotlinCoreEnvironment.kt:572)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:192)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:107)

I don’t really understand how to solve this.

gradle.properties

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
kotlin.version=1.8.20
compose.version=1.4.1

It’s also worth adding that if I go to the main file and press the start button (green play button), then everything works without errors

I tried to change the SDK in project settings → project, changed it to corretto-18, kotlin sdk, openjdk-20.

I also tried replacing gradle.properties with this

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
kotlin.version=1.8.0
compose.version=1.4.1

Can you share your full build.gradle.kts file?

import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    kotlin("jvm")
    id("org.jetbrains.compose")
}

group = "com.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
    google()
}

dependencies {
    // Note, if you develop a library, you should use compose.desktop.common.
    // compose.desktop.currentOs should be used in launcher-sourceSet
    // (in a separate module for demo project and in testMain).
    // With compose.desktop.common you will also lose @Preview functionality
    implementation(compose.desktop.currentOs)
}

compose.desktop {
    application {
        mainClass = "MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "demo5"
            packageVersion = "1.0.0"
        }
    }
}

The only advice I can give you is to try setting different versions of the compose plugin. You can set the version like so:

plugins {
    id("org.jetbrains.compose") version "1.2.1"
}

I’ve got a project using version 1.2.1, but try different versions.

I looked at the two things you’re having problems with in my working project, and I found that my ComposeComponentRegistrar comes from compiler-hosted-1.3.2.3.jar, while ComponentRegistrar comes from kotlin-compiler-embeddable-1.7.10.jar. idk if that helps you… I can try to figure out where Gradle is pulling these files from, to work out what settings you need, but for now, just try different versions of the Compose plugin, and/or Google search the compatibility versions between those two libraries I listed.

Ok so I did a bit of searching and found this StackOverflow question with the same problem. The answer was to make sure the Kotlin version is compatible with the Compose version. The compatibility matrix is here.

So, since you’re using 1.4.1 of Compose, you should be using 1.8.0 of Kotlin. However, I note that in your original post you said you tried that… I would suggest trying that again, but then completely restarting your IDE/computer and maybe even resetting Gradle, somehow.

Hello, unfortunately the error remains (((

Hello. thanks, but I’m confused about whether to take the version from the android website or from JetBrains github.

the compatibility tables are just different there.
I will be grateful if you show me how build.gradle.kts settings.gradle.kts and gradle.properties should look like for kotlin.version=1.9.20