google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.84k stars 266 forks source link

Update to Kotlin 1.8.10 breaks the KSP plugin Arrow Optics code generation #1306

Closed jesperancinha closed 1 year ago

jesperancinha commented 1 year ago

Hello there,

I have two projects where I'm using a special configuration in Maven to generate the source code for arrow optics. The exception I get is:

Error:  Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.8.10:compile (compile) on project jeorg-kotlin-optics-crums-1: Compilation failure
Error:  java.lang.NoClassDefFoundError: org/jetbrains/kotlin/cli/jvm/plugins/ServiceLoaderLite
Error:      at com.google.devtools.ksp.KotlinSymbolProcessingExtension.loadProviders(KotlinSymbolProcessingExtension.kt:83)
Error:      at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:243)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:123)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:257)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
Error:      at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:248)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:88)
Error:      at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
Error:      at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:167)
Error:      at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
Error:      at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:101)
Error:      at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
Error:      at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
Error:      at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execCompiler(KotlinCompileMojoBase.java:228)
Error:      at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:237)
Error:      at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:55)
Error:      at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute(KotlinCompileMojoBase.java:209)
Error:      at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute(K2JVMCompileMojo.java:222)
Error:      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
Error:      at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
Error:      at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
Error:      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
Error:      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
Error:      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
Error:      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
Error:      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
Error:      at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
Error:      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
Error:      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:298)
Error:      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
Error:      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
Error:      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
Error:      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
Error:      at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
Error:      at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
Error:      at java.base/java.lang.reflect.Method.invoke(Method.java:578)
Error:      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
Error:      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
Error:      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
Error:      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Error:  Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.cli.jvm.plugins.ServiceLoaderLite
Error:      at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
Error:      at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
Error:      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
Error:      at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
Error:      ... 42 more
Error:  
Error:  
Error:  -> [Help 1]
Error:  
Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
Error:  Re-run Maven using the -X switch to enable full debug logging.
Error:  
Error:  For more information about the errors and possible solutions, please read the following articles:
Error:  [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Error:  
Error:  After correcting the problems, you can resume the build with the command
Error:    mvn <args> -rf :jeorg-kotlin-optics-crums-1
make: *** [Makefile:4: build-maven] Error 1
Error: Process completed with exit code 2.

Examples of builds that fail are:

The special configuration I'm using in these projects are:

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>${kotlin.version}</version>
    <executions>
        <execution>
            <id>test-compile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
        </execution>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <source>src/main/kotlin</source>
                    <source>target/generated-sources/ksp</source>
                </sourceDirs>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <compilerPlugins>
            <compilerPlugin>ksp</compilerPlugin>
        </compilerPlugins>
        <jvmTarget>${java.version}</jvmTarget>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>com.dyescape</groupId>
            <artifactId>kotlin-maven-symbol-processing</artifactId>
            <version>${kotlin-maven-symbol-processing.version}</version>
        </dependency>
        <dependency>
            <groupId>io.arrow-kt</groupId>
            <artifactId>arrow-optics-ksp-plugin</artifactId>
            <version>${arrow-optics-ksp-plugin.version}</version>
        </dependency>
    </dependencies>
</plugin>

I'm not entirely sure where this bug is coming from. My best guess is that it comes from the KSP plugin but it could also have to do with the dyescape symbol processing dependency which I still need to get optics from project arrow to work. Maybe Kotlin itself has an issue, but I would like to get feedback from you first.

Please let me know your thoughts on this and thanks in advance!

neetopia commented 1 year ago

The error message looks like problems with incompatible binaries, KSP has changed to publish artifacts with the most compatible build flag several versions ago, and the message seems to indicate the incompatibility comes from compiler binaries. That's how I read the message you pasted here.

jesperancinha commented 1 year ago

I moved on and stopped using the Dyescape plugin altogether. I've migrated the affected projects to Gradle. That makes this issue no longer relevant.