Kotlin Help

Kotlin Symbol Processing API

Kotlin Symbol Processing (KSP) is a framework for Kotlin source code generation. With the KSP API, you can create processors that inspect static information about your source code and generate new code from it. The most common use case is generating code based on annotations.

KSP aims to simplify the creation of lightweight compiler plugins. A compiler plugin built with KSP is called a symbol processor, or processor for short. KSP's well-defined API hides compiler changes, so you don't need to spend much effort maintaining your processors. However, this approach comes with trade-offs. For example, KSP-based processors can't examine expressions or statements, and they can't modify the source code.

Typical use cases for KSP-based processors include:

  • Dependency injection (Dagger)

  • Serialization (Moshi)

  • Database management (Room)

To learn how to create your first KSP-based processor, see Getting started with KSP.

Requirements

The latest KSP version, 2.3.12, supports the following dependency versions:

Dependency

Supported versions

Kotlin Gradle plugin (KGP)

2.3.20–2.4.x

Android Gradle plugin (AGP)

8.13.0 or later

Gradle

8.13 or later. For Android projects, also check the AGP and Gradle compatibility table.

JDK

17 or later

How KSP works during compilation

KSP represents Kotlin source code as a hierarchy of symbols based on the Kotlin grammar. Processors then use these symbols to inspect declarations such as classes, functions, properties, and types.

KSP fits into the compilation process as follows:

  1. KSP loads the processors and runs them.

  2. Processors use KSP to analyze the source code and its dependencies. They inspect symbols and types and generate new files, such as source files and resources. Importantly, they cannot modify existing files.

  3. The Kotlin compiler compiles the original source code together with the generated code.

To learn more about KSP, watch this video:

How KSP runs a processor

KSP uses an implementation of SymbolProcessorProvider as the entry point for creating a SymbolProcessor instance:

interface SymbolProcessorProvider { fun create(environment: SymbolProcessorEnvironment): SymbolProcessor }

The SymbolProcessor interface contains the processing logic. KSP calls the process() function and provides a Resolver, which the processor uses to access symbols in the source code:

interface SymbolProcessor { fun process(resolver: Resolver): List<KSAnnotated> fun finish() {} fun onError() {} }

For a step-by-step guide on how to implement and register a processor, see Getting started with KSP.

Supported libraries

The following table lists popular libraries and their various stages of support for KSP:

See also

23 November 2026