How does ksp2 work with the new generatedKotlin So...
# ksp
h
How does ksp2 work with the new generatedKotlin SourceDirectorySet with KGP 2.3? I generate some classes that are wired to the
generatedKotlin
but ksp2 does not resolve these generated classes.
e
KSP plugin does not interact with kotlin plugin (afaik). It runs the kotlin compiler itself, in a task that runs before the kotlin compilation of the build so I doubt it “works with the new generatedKotlin SourceDirectorySet”. (not without ksp doing somethijng custom to support the generated folder)
h
Yeah, I changed my code generator to use the „old“ kotlin SourceDirectorySet and not the new generatedKotlin
t
it is not expected that KSP should look into
generatedKotlin
sources as then it returns to the problem of distinguishing own generated sources from other plugins generated sources. Imho KSP should also provide a way to register additional generated sources that should be analysed as well.
1
h
Hm, but the (gradle plugin of the) code generator does not know ksp, it just generates Kotlin code that is written to an output folder. Do I really need to wire the output folder to a different SourceDirectorySet depending on KMP, Gradle Java plugin, and now also ksp?
And generatedKotlin is also used by IDEA to mark the directory as generated, isn't it?
t
Should your generated sources be analysed by KSP to produce additional generated by KSP sources?
And generatedKotlin is also used by IDEA to mark the directory as generated, isn't it?
Not yet supported, but planned to do so in 2026.1 IDEA release
h
Should your generated sources be analysed by KSP to produce additional generated by KSP sources?
Yes
t
Then, imho, you code generator should be aware of KSP and do KSP specific actions
1
h
Okay, but it is still unrelated. I have an OpenAPI code generator https://github.com/hfhbd/kfx that just generates Kotlin classes from a given OpenAPI file. And I don't care what other users do with the generated code 🤔 And I have a ksp plugin (let's call it sapci) that analyzes the classes, self written and also generated by kfx. While I can also switch my sapci from ksp to a Kotlin compiler plugin, I don’t understand why kfx needs to be aware of ksp, while it's only a „problem“ of the usage when using the sapci ksp plugin.
BTW ksp2 uses AA, dokka too. Will dokka also won't see classes stored in generatedKotlin?
1
e
@hfhbd my question would be: are you sure you really need to use
generatedKotlin
? I mean, nothing wrong with simply associating generated sources to a normal Kotlin source set imo, it's what we did up until now. Or have you got strong reasons to prefer the new way?
h
No, I don't need it, that's why I also reverted it in kfx. But I would like to use the new feature in the future.
e
nothing wrong with simply associating generated sources to a normal Kotlin source set imo
There is a reason why generated kotlin was introduced. Code coverage, code style & static analysis tools running on generated sources is very undesirable. Also, IDE can properly now distinguish between generated and handwritten source. Imo, all generated source should go in the generated folder, even for correctness sake its the right thing to do. We will just need to figure out the right mode of operation or integration with all the tools.
4