I have a project that includes two KSP processors....
# ksp
r
I have a project that includes two KSP processors. One KSP processor contributes code that contains annotations that are used by the second KSP processor, OSS project Zodable (https://github.com/guimauvedigital/zodable/tree/main/zodable-ksp-processor). In debugging this, I see that the Zodable processor is called twice -- once with the original set of annotated classes, then again with the new generated set of annotated classes from the first processor. The Zodable processor writes some stuff to disk, but it currently assumes it is only called once, so the second execution of it borks the output. What would the right way to fix this in the Zodable processor be? I thought about appending to those outputs but that doesn't work for incremental builds where the outputs already exist.
I'm looking into https://kotlinlang.org/docs/ksp-incremental.html#aggregating-vs-isolating -- maybe if I specify the dependencies as aggregating it will work out of the box? I'm also looking at potentially using the invalidation logic from https://kotlinlang.org/docs/ksp-multi-round.html.
I ended up just incrementing a counter to know what round I was in, and if after the first, to append instead of overwrite. Seems simple enough but I'd be happy for the experts to let me know there is a better approach. https://github.com/guimauvedigital/zodable/pull/25/commits/ff8b96b4eabb319c24a5450b81d6a688cd511c9b I also added incremental processing, but since it is using multiple rounds I could not use
createNewFile
with an aggregating Dependency as I wanted to. https://github.com/guimauvedigital/zodable/pull/25/commits/5889b323a329d12eefd213f5b72a73db3a3f8d8a