kmp-kotlinpoet

Generates Kotlin source at compile time by authoring KSP annotation processors with KotlinPoet builders.

2|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-kotlinpoet-ronjunevaldoz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kmp-kotlinpoet
Source: https://github.com/ronjunevaldoz/kmp-agent-skills/tree/main/skills/kmp-kotlinpoet
Command: npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-kotlinpoet-ronjunevaldoz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing a custom KSP annotation processor involves many failure-prone details: hand-built string templates produce broken generated code, a missing ServiceLoader registration file makes the processor silently never run, and skipping originating-file tracking breaks incremental compilation. This Skill provides the verified patterns for authoring a new processor that generates type-safe Kotlin source with KotlinPoet. ## Core Features & Use Cases - KotlinPoet builder API: FileSpec, TypeSpec, FunSpec, and PropertySpec builders with format specifiers (%S, %T, %M, %N, %L, %P) that resolve imports and escape strings automatically. - Two-module processor structure: an annotations module plus a JVM processor module wired via ServiceLoader registration in META-INF/services, consumed with ksp(project(":processor")). - kotlinpoet-ksp interop: convert KSP KSType and KSClassDeclaration into KotlinPoet TypeName and ClassName using toTypeName(), toKModifier(), and TypeParameterResolver. - Use Case: Define a @GenerateKoinModule annotation, then build a processor that scans annotated classes and emits a Koin module with a factoryOf binding per class, with Dependencies tracking for incremental compilation. ## Quick Start Ask the agent to create a custom KSP annotation processor that generates Kotlin source with KotlinPoet for a given annotation and target output.

Frequently Asked Questions about kmp-kotlinpoet

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom KSP annotation processor in Kotlin?▼

Create two modules: an annotations module holding the annotation and a JVM processor module implementing SymbolProcessor and SymbolProcessorProvider. Register the provider in META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider, then consume it with ksp(project(":processor")).

KSP vs kapt for annotation processing, which should I use?▼

KSP is the recommended choice for new processors. It runs up to twice as fast because it skips kapt's intermediate Java stub generation, and its API is lazy by design. There is no real reason to reach for kapt for a new processor.

Why is my KSP processor not running or generating any code?▼

The most common cause is a missing META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider registration file. The processor compiles fine but silently never runs without it. Also verify the KSP version matches the project's Kotlin compiler version.

How do I convert KSP KSType to KotlinPoet TypeName?▼

Use the kotlinpoet-ksp interop module: call toTypeName() on a KSType, toClassName() on a KSClassDeclaration, and toKModifier() for modifiers. For generic types, resolve with a TypeParameterResolver so type parameters keep their declaring scope.

Why does my KSP processor not re-run when source files change?▼

The processor is missing originating-file tracking. Pass a Dependencies object built from the annotated classes' containing files when calling fileSpec.writeTo(codeGenerator, dependencies). Without it, incremental compilation breaks and stale generated files ship.

When should I not use KotlinPoet for code generation?▼

Do not use it to consume an already-published KSP processor like Koin's annotated mode or Room, since that is ordinary dependency usage. It also does not apply outside the JVM, such as Python scripts emitting Kotlin text where no JVM classpath exists.