Migrate from kapt to KSP

Kapt (the Kotlin Annotation Processing Tool) lets you use Java annotation processors with Kotlin code, even if those processors don't have specific support for Kotlin. This is done by generating Java stubs from your Kotlin files that the processors can then read. This stub generation is an expensive operation and has a significant impact on build speed.

KSP (Kotlin Symbol Processing) is a Kotlin-first alternative to kapt. KSP analyzes Kotlin code directly, which is up to 2x faster. It also has a better understanding of Kotlin language constructs.

You can run kapt and KSP alongside each other in your project while you're migrating, and the migration can be done module by module, library by library.

Here's an overview of the migration steps:

  1. Check the libraries you use for KSP support
  2. Add the KSP plugin to your project
  3. Replace annotation processors with KSP
  4. Remove the kapt plugin

Check the libraries you use for KSP support

To get started, check if the libraries you're using with kapt already have KSP support. This is the case for many popular libraries (including Dagger, Glide, Room, and Moshi), and others are adding support.

You can check the list of supported libraries in the documentation, or refer to the documentation and issue tracker of the libraries you're using.

Add the KSP plugin to your project

First, declare the KSP plugin in your top level build.gradle.kts file. You can find a list of releases on the KSP GitHub page.

Kotlin

plugins{
id("com.google.devtools.ksp")version"2.3.4"applyfalse
}

Groovy

plugins{
id'com.google.devtools.ksp'version'2.3.4'applyfalse
}

Then, enable KSP in your module-level build.gradle.kts file:

Kotlin

plugins{
id("com.google.devtools.ksp")
}

Groovy

plugins{
id'com.google.devtools.ksp'
}

Replace annotation processors with KSP

With KSP enabled, you can start replacing usages of kapt with KSP. For a vast majority of libraries, this just requires changing kapt to ksp at the dependency declaration, as they ship their annotation processor and KSP processor in the same artifact.

Kotlin

dependencies{
(削除) kapt("androidx.room:room-compiler:2.5.0") (削除ここまで)
ksp("androidx.room:room-compiler:2.5.0")
}

Groovy

dependencies{
(削除) kapt'androidx.room:room-compiler:2.5.0' (削除ここまで)
ksp'androidx.room:room-compiler:2.5.0'
}

After moving to KSP, sync and build your project to see if it still works correctly.

Some common issues to look out for:

  • Some libraries don't support the exact same set of features with kapt and KSP. If your code breaks after migrating, check the library's documentation.
  • KSP has more accurate Kotlin type information than kapt (for example, about nullability), which means that KSP processors can be more precise about type requirements. This might require some fixes in your source code as well, in addition to updating your build files.
  • If you were previously passing in arguments to the annotation processor, you'll likely need to pass in those arguments to KSP now. Note that the format of the arguments might differ between kapt and KSP. See the KSP documentation and consult the documentation of the library you're using to learn more.

Remove the kapt plugin

When you have no dependencies included with kapt in your module anymore, remove the kapt plugin.

If it was declared in a plugins block:

Kotlin

plugins{
(削除) id("org.jetbrains.kotlin.kapt") (削除ここまで)
}

Groovy

plugins{
(削除) id'org.jetbrains.kotlin.kapt' (削除ここまで)
}

If it was using the apply plugin syntax using Groovy:

(削除) apply plugin: 'kotlin-kapt' (削除ここまで)

You should also remove any leftover configuration related to kapt, such as:

Kotlin

(削除) 
kapt{
correctErrorTypes=true
useBuildCache=true
}
 (削除ここまで)

Groovy

(削除) 
kapt{
correctErrorTypestrue
useBuildCachetrue
}
 (削除ここまで)

Additional resources

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026年01月14日 UTC.