Kotlin Help

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:

plugins { id("com.google.devtools.ksp") version "2.3.6" apply false }
plugins { id 'com.google.devtools.ksp' version '2.3.6' apply false }

Update your processor

Find the module that uses the processor you want to migrate. In the module's build.gradle(.kts) file:

  1. Add KSP to the plugins {} block:

    plugins { id("com.google.devtools.ksp") }
    plugins { id 'com.google.devtools.ksp' }
  2. In the dependencies {} block, replace kapt with ksp:

    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:

plugins { // Delete this line: id("org.jetbrains.kotlin.kapt") }
plugins { // Delete this line: id 'org.jetbrains.kotlin.kapt' }

Delete any leftover kapt configurations if you have them.

What's next?

28 April 2026