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 or explicit
@MapNested, with implicit child mapper generation - 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 - Reverse mapping —
@MapReversegenerates the inverse mapper automatically - 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¶
// 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>")
}
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