Does KSP make sense for a use case where I just ne...
# ksp
z
Does KSP make sense for a use case where I just need to read annotations and not generate any Kotlin code? (I just need to generate some JSON or YAML based on what functions are annotated with a specific annotaiton)
g
(afaiu) KSP doesn't help you write kotlin code (KotlinPoet usually does that), it helps "scanning" the code. KSP offers you a way to write a file (CodeGenerator.createNewFile) which accepts an extension. If the extension is "kt" (or "java" I suppose), then it will be handled as code and go in src/main/kotlin (see multiple round processing), if the extension is "json" for example, then it will go under src/main/resources and not be considered as code at all. I'm using it for non kt file, no problem so far, so given the API I understand it's totally ok to write those files from KSP.
j
There's an open issue related to this; I don't think there's a way to generate code that doesn't land in the build, but you can work around that limitation: https://github.com/google/ksp/issues/1677