Overview
The Build Constants feature generates a Kotlin object at compile time that exposes key-value pairs as const val string properties. This allows you to embed information like the project version, name, or any custom value directly into your compiled code — without runtime lookups or manual maintenance.
Build constants generation is disabled by default. Enable it inside the buildConstant { } block within kreate { project { } }:
How It Works
When enabled, Kreate registers a kreate-build-constants Gradle task that runs automatically before compilation. The task uses KotlinPoet to write a .kt source file into the build directory and wires it into the project's source sets so it is compiled alongside your regular code.
The generated file is placed at:
build/generated/compile/<packagePath>/<ClassName>.kt
It is added automatically to commonMain for Kotlin Multiplatform projects, or to main for Kotlin JVM projects.
Generated Output
Given the following configuration:
Kreate generates a file at build/generated/compile/com/example/mylibrary/build/BuildConstants.kt:
You can then import and use it anywhere in your code:
Next Steps
Configuration Reference: Customize package names, class names, and target source sets
Examples: Advanced usage, including environment variables and dynamic values