Kreate v1.2.3 Help

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 { } }:

kreate { project { buildConstant { enabled.set(true) } } }

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 { project { name = "MyLibrary" projectGroup = "com.example" buildConstant { enabled.set(true) constant("version", project.version) constant("name", "MyLibrary") } } }

Kreate generates a file at build/generated/compile/com/example/mylibrary/build/BuildConstants.kt:

// This file is generated automatically. // Do not edit or modify! Changes will be overwritten on the next build. // Generated on 2026-04-25 10:00:00. package com.example.mylibrary.build /** * Auto-generated build constants. */ object BuildConstants { const val VERSION: String = "1.0.0" const val NAME: String = "MyLibrary" }

You can then import and use it anywhere in your code:

import com.example.mylibrary.build.BuildConstants println(BuildConstants.VERSION) println(BuildConstants.NAME)

Next Steps

  • Configuration Reference: Customize package names, class names, and target source sets

  • Examples: Advanced usage, including environment variables and dynamic values

26 April 2026