Kraft¶
Compile-time mapper generation for Kotlin Multiplatform.
Kraft is a KSP-based annotation processor that generates type-safe extension functions to map between data classes. No reflection, no runtime overhead — just clean, generated Kotlin code.
Features¶
- Annotation-driven —
@MapConfig,@MapFrom, or@MapToto declare mappings - Property matching — same-name properties mapped automatically
- Field renaming —
@MapFieldor@FieldMappingfor cross-name mapping - Nested objects — auto-detected when types differ, with implicit child mapper generation; use
@MapField/FieldMappingfor renamed pairs (@MapNestedis deprecated) - Collections —
List<T>andSet<T>with nested element mapping - Enum mapping —
@MapEnumwith auto-matching and custom entry pairs - Custom converters —
@MapUsingfor property-source or whole-source transformations - Global converters —
@KraftConverteron a top-level extension is auto-discovered across the module and the classpath, with@OptInmarkers propagated onto the generated mapper - Reverse mapping —
@MapReversegenerates the inverse mapper automatically - Layer-aware aliases — register
Dto/Domain/Entitysides via Gradle to emit short.toDomain()/.toEntity()extensions alongside the verbose mappers - Ignore rules —
@MapIgnoreand@MapIgnoreFieldwith directional control - Plugin SPI — implement
MapperGeneratorProviderto plug in your own code generator - Kotlin Multiplatform — annotations work on JVM, iOS, JS, and WasmJs
Quick Start¶
JVM / Android:
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "2.3.3"
}
dependencies {
implementation("com.blu3berry.kraft:kraft-annotations:<version>")
ksp("com.blu3berry.kraft:kraft-ksp:<version>")
}
Kotlin Multiplatform:
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "2.3.3"
}
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.blu3berry.kraft:kraft-annotations:<version>")
}
}
}
dependencies {
add("kspCommonMainMetadata", "com.blu3berry.kraft:kraft-ksp:<version>")
}
See Getting Started for full installation details.
data class User(val id: Int, val name: String, val email: String)
data class UserDto(val id: Int, val name: String, val email: String)
@MapConfig(source = User::class, target = UserDto::class)
object UserMapper
// Generated: fun User.toUserDto(): UserDto
Documentation¶
- Getting Started — installation and first mapper
- User Guide — all features with examples
- Architecture — internals and SPI guide
- Contributing — how to contribute
- AI Integration — use Kraft with AI coding agents