Migrate from kapt to KSP
In this guide, you will learn how to migrate your annotation processors from kapt to KSP so that your project can take full advantage of Kotlin features and improve build performance.
kapt (Kotlin Annotation Processing Tool) is a useful tool that lets you use Java annotation processors in Kotlin. It works by translating Kotlin source code into Java "stubs" and then running the annotation processors on those stubs. However, this process is expensive, significantly increases build time, and loses some Kotlin-specific features in translation.
In contrast, KSP (Kotlin Symbol Processing) is an alternative to kapt designed specifically for Kotlin. KSP understands all Kotlin features and analyzes the source code directly, reducing build time.
Before you begin, check whether the processors in your project support KSP. See the list of supported libraries or consult their documentation.
Add the KSP plugin to your project
Add KSP to the plugins {} block in the project-level build.gradle(.kts) file:
Update your processor
Find the module that uses the processor you want to migrate. In the module's build.gradle(.kts) file:
Add KSP to the
plugins {}block:plugins { id("com.google.devtools.ksp") }plugins { id 'com.google.devtools.ksp' }In the
dependencies {}block, replacekaptwithksp:dependencies { implementation("com.google.dagger:dagger:2.48") // kapt("com.google.dagger:dagger-compiler:2.48") // KSP processor dependency: ksp("com.google.dagger:dagger-compiler:2.48") }dependencies { implementation 'com.google.dagger:dagger:2.48' // kapt 'com.google.dagger:dagger-compiler:2.48' // KSP processor dependency: ksp 'com.google.dagger:dagger-compiler:2.48' }
Remove the kapt plugin
After migrating all your processors to KSP, you can safely remove the kapt plugin from all build files:
Delete any leftover kapt configurations if you have them.
What's next?
Learn how to make your own KSP-based annotation processor in Getting started with KSP.
Explore example projects that use KSP in the KSP repository.
Read more about KSP in the Overview.