https://kotlinlang.org logo
#ksp
Title
# ksp
n

Norbi

11/29/2023, 5:46 PM
My use case: 1.
ProcessorA
generates class
a.b.ClassA
2.
ProcessorB
enumerates declarations in package
a.b
using
com.google.devtools.ksp.processing.Resolver#getDeclarationsFromPackage
and generates one aggregated class
a.b.Aggregated
from them. If
ProcessorB
is executed before
ProcessorA
then
ProcessorB
is called one more time for a round#2. I tried to cache data about the classes processed in round#1 in the
ProcessorB
instance but when I try to regenerate
a.b.Aggregated
in round#2 then a
kotlin.io.FileAlreadyExistsException: .../Aggregated.kt
exception is thrown, despite using
aggregating = true
. Maybe do you have an idea what should I try? Thanks.
I use ksp 1.9.10-1.0.13 - maybe I should try to upgrade? EDIT: I upgraded to 1.9.21-1.0.15 but it still fails with
FileAlreadyExistsException
.
e

ephemient

11/29/2023, 6:13 PM
aggregating doesn't mean you can overwrite previous outputs
🙏 1
n

Norbi

11/29/2023, 7:22 PM
As I understand, my use-case cannot be implemented with KSP currently...
e

ephemient

11/29/2023, 7:33 PM
you should be able to gather all the names as
process
is called through multiple rounds (make sure not to cache the symbols themselves, https://kotlinlang.org/docs/ksp-multi-round.html#information-consistent-cross-rounds) and then write out the aggregation in
finish
today i learned 1
n

Norbi

11/29/2023, 9:01 PM
I haven't noticed
finish()
until now (probably simply because there was no need for it 🙂 ). Thanks for the very useful idea.
3 Views