livefront / sealed-enum

A Kotlin annotation processor that makes writing normal enum classes obsolete.
Apache License 2.0
149 stars 7 forks source link

With Kotlin 1.8, kapt tries to compile generated Java classes using Kotlin #119

Closed gwilliams-livefront closed 1 year ago

gwilliams-livefront commented 1 year ago

When updating our project from Kotlin 1.7.10 to 1.8.10, I got an error for all the @GenSealedEnum companion objects in our project. For some reason kapt was expecting Kotlin classes, but the generated classes were Java code. Here's an example of the error message:

[project]/app/build/tmp/kapt3/stubs/debug/com/[redacted]/processor/pricelist/PriceSortOrder.java:139: error: Annotated element is not a Kotlin class
    public static final class Companion {

I was able to switch to ksp and everything generated properly.

Here's relevant lines from build.gradle.kts

buildscript {
   dependencies {
       ...
       classpath(kotlin("gradle-plugin", version = "1.7.10"))
       ...
   }
}

...

plugins {
    id("com.android.application")
    kotlin("android")
    kotlin("kapt")
    ...
}

dependencies {
    ...
    implementation("com.github.livefront.sealed-enum:runtime:0.5.0")
    kapt("com.github.livefront.sealed-enum:processor:0.5.0")
    ...
}
alexvanyo commented 1 year ago

Thanks for the report! I saw the same issue updating the project itself to 1.8, it looks like a dependency bump will resolve the issue as drafted in #120.

It's good to know that ksp is working fine and that should be a better experience going forward anyway, at some point it might make sense to deprecate the kapt version entirely.

alexvanyo commented 1 year ago

kotlinpoet 1.13.0 was just released, which unblocks #120.

alexvanyo commented 1 year ago

0.6.0 released with the update to Kotlin 1.8