Error message when building Kotlin and Jetpack Compose desktop project: ComposeComponentRegistrar plugin not compatible

2.5k Views Asked by At

I am currently developing a desktop project with Kotlin, Jetpack Compose, and Gradle in IntelliJ. I am experiencing a problem during the build phase, where I receive the following error message:

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:666)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:168)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.configureProjectEnvironment(KotlinCoreEnvironment.kt:569)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:198)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:107)

This is my buil.gradle.kts:

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

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

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

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

kotlin {
    jvm {
        jvmToolchain(11)
        withJava()
    }
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs)
            }
        }
        val jvmTest by getting
    }
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "demo"
            packageVersion = "1.0.0"
        }
    }
}

These are the current settings of my gradle.properties file (I tried different settings, but without success):

kotlin.code.style=official
kotlin.version=1.8.0
agp.version=7.3.0
compose.version=1.3.0

I have attempted to use different versions of Kotlin and Jetpack Compose, but I still encounter the same error. It is important to note that the program runs correctly if compiled. I was expecting the project to build successfully without any errors.

2

There are 2 best solutions below

1
On

For me this error was caused by my Intellij Gradle configuration: selecting 'Gradle (Default)' for build and run in Settings > Build, Execution, Deployment > Build Tools > Gradle instead of 'Intellij IDEA' resolved the issue for me.

Intellij Configuration

I used the following 'gradle.properties':

kotlin.code.style=official
kotlin.version=1.8.20
agp.version=7.3.0
compose.version=1.4.0
1
On

This error occurs when there is a mismatch between the version of the Kotlin compiler and the Compose compiler plugin. To fix this error, you need to make sure that the versions of the Kotlin compiler and Compose compiler plugin are compatible.

In your case, you are using Kotlin 1.8.0, which is not a valid version. You should update the version to the latest stable version, which is currently 1.6.10.

Also, since you are using Jetpack Compose version 1.3.0, you should use the Compose compiler plugin version that is compatible with it. According to the Compose documentation, version 1.0.5 of the Compose compiler plugin is compatible with Jetpack Compose version 1.3.0.

To fix the error, you can update your gradle.properties file to the following:

kotlin.code.style=official
kotlin.version=1.6.10
agp.version=7.3.0
compose.version=1.3.0

Then, update your build.gradle.kts file to use version 1.0.5 of the Compose compiler plugin:

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

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose") version "1.0.5"
}

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

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

kotlin {
    jvm {
        jvmToolchain(11)
        withJava()
    }
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs)
            }
        }
        val jvmTest by getting
    }
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "demo"
            packageVersion = "1.0.0"
        }
    }
}

After updating your files, sync your Gradle project and try building again. This should resolve the error.