jeppeman / mockposable

Mocking with Jetpack Compose - stubbing and verification of Composable functions
Apache License 2.0
37 stars 3 forks source link

Kotlin 2.0 support #23

Closed frett closed 1 day ago

frett commented 2 weeks ago

When upgrading our project to Kotlin 2.0 we are running into several errors related to this plugin.

The first error we run into is:

A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: Starting in Kotlin 2.0, the Compose Compiler Gradle plugin is required
  when compose is enabled. See the following link for more information:
  https://d.android.com/r/studio-ui/compose-compiler

This looks to be caused by the plugin using the old Android compose compiler plugin. With Kotlin 2.0 the standalone android plugin was replaced with a plugin that gets bundled with the Kotlin release directly. See: https://android-developers.googleblog.com/2024/04/jetpack-compose-compiler-moving-to-kotlin-repository.html

I was able to bypass this error by using a gradle resolutionStrategy to replace the android compose compiler with the new kotlin compose compiler.

configurations.configureEach {
    resolutionStrategy.dependencySubstitution {
        substitute(module("androidx.compose.compiler:compiler"))
            .using(module("org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:2.0.0"))
    }
}

This revealed the next error related to upgrading to Kotlin 2.0:

e: There are some plugins incompatible with language version 2.0:
  com.jeppeman.mockposable.compiler.MockposablePlugin
Please use language version 1.9 or below
jeppeman commented 2 weeks ago

Hey @frett, thanks for reporting. Will look into this during the day

jeppeman commented 2 days ago

Hi @frett, sorry for the delay, got busy and forgot about this. I've published a snapshot (0.9-SNAPSHOT) with support for 2.0 now though, could you try and see if it works for you? Make sure you add the snapshots repo

maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
frett commented 1 day ago

thanks for working on the issue, I'll try and take a look at the SNAPSHOT today.

frett commented 1 day ago

everything compiles and tests pass with 0.9-SNAPSHOT

jeppeman commented 1 day ago

Thanks for verifying, I've published 0.9 now, it should be synced to mavenCentral in a couple of hours or so.