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

David Herman

03/08/2024, 8:01 PM
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

Ting-Yuan Huang

03/09/2024, 3:14 AM
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

David Herman

03/09/2024, 3:15 AM
Thanks! It might be good to document this in the project README or blog post maybe?
t

Ting-Yuan Huang

03/09/2024, 3:17 AM
Yes, and we should have done it a couple of months ago 😢 I'll try my best to do it next week.
d

David Herman

03/09/2024, 3:17 AM
Appreciate it!
6 Views