Google has rolled out the alpha version of Kotlin Symbol Processing (KSP), an API for building lightweight compiler plug-ins in the Kotlin language.
Similar to the Kapt compiler plug-in for annotation processing, but said to be faster, KSP offers direct access to Kotlin compiler capabilities. Implemented as a compiler plug-in itself, KSP is designed to obscure compiler changes and minimize maintenance efforts.
KSP features an API for directly parsing Kotlin code, to reduce the build speed tax imposed by Kapt stub generation. Kotlin faces a challenge in that it lacks a native annotation processing system, although annotation processors such as Room exist for Kotlin, Google said in a bulletin published on February 10.
A library supporting KSP resembles a normal annotation processor, albeit faster. Note that using Kapt and KSP in the same module likely will slow down a build initially. Thus, during the alpha phase, it is advised that KSP and Kapt be maintained in separate modules. As more annotation processors adopt KSP, the tool is expected to become a drop-in replacement for Kapt.
Kotlin has become a viable choice for Android application development. But KSP is being developed with the goal of it being multiplatform; thus it is not tied to the JVM. Compatible with Kotlin 1.34.0, KSP has been likened to a preprocessor framework for Kotlin programs.
KSP source code and documentation can be found in GitHub. Developers can see what KSP looks like in action via the KSP Playground project, accessible via a link in the bulletin on the project. With the API still in development and likely to change, it is not advisable yet to use KSP in production.