Is there any guidance or example project for how t...
# ksp
d
Is there any guidance or example project for how to use KSP2? All I could find is https://android-developers.googleblog.com/2023/12/ksp2-preview-kotlin-k2-standalone.html which only feels like it scratches the surface and left me with so many questions as to how to proceed.
Copy code
val kspConfig = KSPJvmConfig.Builder().apply {
  // All configurations happen here.
}.build()
val exitCode = KotlinSymbolProcessing(kspConfig, listOfProcessors, kspLoggerImpl).execute()
☝️ from the post. Where does this code even go? What does my build.gradle.kts file look like? What does migrating from KSP to KSP2 look like?
t
If you're using KSP's Gradle plugin, just set the Gradle property
ksp.useKSP2
to true and use it as if it was KSP1. To use KSP2 without KSP's Gradle plugin, e.g., without the
ksp(some_processor)
dependencies, you'll only need
implementation("com.google.devtools.ksp:symbol-processing-aa-embeddabe:<version>")
in
build.gradle.kts
. The
val kspConfig...
snippet is placed in your main or test entry points. For example, you'll need to setup
sourceRoots
and
javaSourceRoots
to tell KSP where to find the source files, and
kotlinOutputDir
to write generated Kotlin files. Here are a few examples that fill up the config and calls KSP: 1. KSP's test code 2. KSP's Gradle plugin. This one creates a clean classpath and is a bit complicated.
d
Thanks! It might be good to document this in the project README or blog post maybe?
t
Yes, and we should have done it a couple of months ago 😢 I'll try my best to do it next week.
d
Appreciate it!