Migrate from kapt to KSP
This guide explains how to migrate your annotation processors from Kotlin Annotation Processing Tool (kapt) to Kotlin Symbol Processing (KSP). Your project can take full advantage of Kotlin features and improve build performance.
kapt lets you use Java annotation processors in Kotlin. It translates Kotlin source code into Java "stubs" and then runs 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 is an alternative to kapt designed specifically for Kotlin. KSP reduces build time by analyzing Kotlin source directly and exposing Kotlin-specific information like nullability.
Before you start
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 the KSP plugin to the plugins {} block in the project-level build.gradle(.kts) file:
Replace kapt with KSP in your modules
Find the module that uses the processor you want to migrate. In the module's build.gradle(.kts) file:
Add the KSP plugin to the
plugins {}block:// build.gradle.kts plugins { id("com.google.devtools.ksp") }// build.gradle plugins { id 'com.google.devtools.ksp' }In the
dependencies {}block, replacekaptwithksp:// build.gradle.kts dependencies { implementation("com.google.dagger:dagger:2.48") // Replaces kapt("com.google.dagger:dagger-compiler:2.48") ksp("com.google.dagger:dagger-compiler:2.48") }// build.gradle dependencies { implementation 'com.google.dagger:dagger:2.48' // Replaces kapt 'com.google.dagger:dagger-compiler:2.48' ksp 'com.google.dagger:dagger-compiler:2.48' }
For most libraries, this replacement is enough. Check each library's documentation to see if you need to make any additional changes.
Remove the kapt plugin
After migrating all your processors to KSP, you can safely remove the kapt plugin from all build.gradle(.kts) files:
Delete any leftover kapt configuration, such as the kapt {} block, if you have it.
See also
Learn how to create your own processor with the KSP API.
Find the KSP equivalents of Java annotation processing APIs in the Java annotation processing to KSP reference.
Learn how KSP works during compilation in the Kotlin Symbol Processing API overview.
Explore the example projects in the KSP repository.