https://kotlinlang.org logo
#kapt
Title
# kapt
y

Yurii Surzhykov

02/29/2024, 7:08 PM
Good day everyone! I have a question about KAPT(or maybe about KSP). I'm trying to write own ksp plugin to automatically generate Room's DAOs, database class, entities based on the classes created by me. There is custom annotation -
@PersitableEvent
, which is used to annotate the class for which my KSP plugin have to generate entity class, mapper class, DAO interface and there is also autogenerated database class with all those DAOs. The situation is the following, let's assume there is a class
Copy code
@PersitableEvent
data class PreviouslyCreatedClass(
  val someProperty: String
)
The problem is next. When I'm trying to compile everything from scratch(without '_build/generated'_ folder), everything works as expected, each class is generated and everything compiles and runs. But then, I'm adding a new class with
@PersitableEvent
annotation, and ksp task completes successfully, but kapt shows me error: kaptGenerateStubsDebugKotlin: Unresolved reference
PreviouslyCreatedClassDao
in my AutoGeneratedDatabase class. And there is also message below this error: kaptGenerateStubsDebugKotlin: Failed to restore task output as snapshot file app/build/snapshot/kotlin/kaptGenerateStubsDebugKotlin/2.zip does not exist! I don't understand what is wrong with it, but when I compile again, it compiles successfully(maybe because second time it compiles everything from scratch and not uses cache). Can someone explain me what the error means, and how to solve it? Currently I removed kapt plugin and the error is disappeared but I would probably need kapt in the future(for dagger). P.s.
PreviouslyCreatedClassDao
is an autogenerated class P.p.s My Kotlin version is 1.9.20, and ksp version is 1.9.20.-1.0.14
e

ephemient

03/01/2024, 1:15 AM
kapt and ksp do not have any inherent ordering or dependency relationship, so you cannot tell rely on files generated by one to be visible to the other - they may or may not be
consider changing to room's ksp processor instead of its kapt processor, or switching your own ksp processor to kapt
then it'll depend on how well it handles multi-round processing, but at least then there's a possibility that it may work
y

Yurii Surzhykov

03/01/2024, 1:24 AM
@ephemient I don't use kapt for Room, I use ksp for it as well. But I had a kapt plugin applied to my project, and it was giving me that error. I removed it for a while, until I will need kapt possibly for dagger, but still wondering what does this error mean.
e

ephemient

03/01/2024, 1:32 AM
then it's possible room doesn't handle multi-round processing
2 Views