Kraft
0.10.0indexedCompile-time generation of type-safe extension mappers between data classes, with automatic property matching, renaming, nested and collection mapping, enum conversion, custom converters, and reverse mappers.
Compile-time generation of type-safe extension mappers between data classes, with automatic property matching, renaming, nested and collection mapping, enum conversion, custom converters, and reverse mappers.
Compile-time mapper generation for Kotlin Multiplatform, powered by KSP.
Kraft generates type-safe extension functions to map between data classes. No reflection, no runtime overhead — just clean, generated Kotlin code.
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)
UserMapper
dto = user.toUserDto()
Kraft runs entirely at build time; the generated mappers are plain Kotlin and the annotations target JVM 1.8, so legacy apps on older runtimes are supported — see Compatibility and legacy projects.
Kraft is published to Maven Central under the com.blu3berry.kraft group (latest version shown in the badge above). Make sure mavenCentral() is in your repositories { } block, then add the dependencies below — replace <version> with the current release.
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.blu3berry.kraft:kraft-annotations:<version>")
}
}
}
dependencies {
add("kspCommonMainMetadata", "com.blu3berry.kraft:kraft-ksp:<version>")
}
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}
dependencies {
implementation("com.blu3berry.kraft:kraft-annotations:<version>")
ksp("com.blu3berry.kraft:kraft-ksp:<version>")
}
Copyright Kraft Contributors
Licensed under the Apache License, Version 2.0
See LICENSE for the full text.
@MapField or @FieldMapping for cross-name mappingList<T> and Set<T> with nested element mapping@MapEnum with auto-matching and custom entry pairs@MapUsing for property-source or whole-source transformations@KraftConverter on a top-level extension is auto-discovered across the module and the classpath, with @OptIn markers propagated onto the generated mapper@MapReverse generates the inverse mapper automaticallyDto / Domain / Entity sides via Gradle to emit short .toDomain() / .toEntity() extensions alongside the verbose mappers@MapIgnore and @MapIgnoreField with directional control@MapConfig for mapping without modifying data classesMapperGeneratorProvider to plug in your own code generator| Annotation | Purpose | Placement |
|---|
@MapConfig | Standalone mapping config | On object |
@MapFrom | Map from source class | On target data class |
@MapTo | Map to target class | On source data class |
@MapField | Rename a property | On property in @MapFrom/@MapTo class |
@MapNested | On property in @MapFrom/@MapTo class | |
@MapIgnore | Skip a property | On property (must have default value) |
@MapUsing | Custom converter function | On function in @MapConfig object |
@KraftConverter | Globally discoverable converter | On top-level extension function |
@MapEnum | Enum-to-enum mapping | On object |
@MapReverse | Generate inverse mapper | On class or @MapConfig object |
aliasEmitMode | Per-mapper alias control (AliasEmitMode enum) | Parameter on @MapConfig and @MapEnum |
ConverterDirection | Direction selector for @MapUsing (AUTO / FORWARD / REVERSE) | Parameter on @MapUsing(direction = …) |
IgnoreSide | Direction selector for @MapIgnoreField (TARGET / SOURCE / BOTH) | Parameter on @MapIgnoreField(direction = …) |
@FieldMapping | Config-level rename | In @MapConfig.fieldMappings |
@NestedMapping | In @MapConfig.nestedMappings | |
@MapIgnoreField | Config-level ignore | In @MapConfig.ignoredMappings |
Surfaced from shared tags and platforms — no rankings paid for.