KEnv Config
Type-safe, schema-driven environment configuration for Kotlin Multiplatform and Android.
KEnv Config is a Gradle plugin that generates Kotlin objects from YAML schema files and environment-specific value files. It catches missing values at compile time, supports multiple environments, and provides IDE documentation through KDoc generation.
Installation
Version Catalog (TOML) — Recommended
# gradle/libs.versions.toml
[versions]
kenvConfig = "0.2.0"
[plugins]
kenvConfig = { id = "io.github.adventures92.kenv-config", version.ref = "kenvConfig" }
// build.gradle.kts
plugins {
alias(libs.plugins.kenvConfig)
}
Direct Application
// build.gradle.kts
plugins {
id("io.github.adventures92.kenv-config") version "0.2.0"
}
Quick Start
kenvConfig {
directory.set(file("kenv"))
environments.set(listOf("dev", "production"))
generatedPackageName.set("com.example.config")
}
Then access your config in code:
// Flat access after setting active environment (KMP)
EnvConfig.setActiveEnvironment("production")
val apiUrl = EnvConfig.Server.API_BASE_URL
// Or direct per-environment access
val devUrl = EnvConfig.Dev.Server.API_BASE_URL
val prodUrl = EnvConfig.Production.Server.API_BASE_URL
Documentation
- Getting Started — Full setup walkthrough
- Schema Reference — Types, scopes, groups, env file formats
- Plugin Configuration — DSL options, tasks, error messages
- Android Variant Mapping — Per-build-type code generation
- Runtime Environment Selection — KMP environment switching
- Code Generation — Generated code structure and behavior
Features
- Type-safe — Generated Kotlin objects with correct types (String, Int, Long, Double, Float, Boolean, Url)
- Compile-time validation — Missing values are caught during build, not at runtime
- Multi-environment — Dev, staging, production — as many as you need
- KMP compatible — Works in commonMain with runtime environment selection
- Android variant mapping — Automatic per-build-type code generation
- KDoc generation — Schema descriptions become IDE-visible documentation
- Groups — Organize variables into logical nested objects
- Unified directory — Single
kenv/directory for all config files - Multi-format — Environment files in
.env,.yaml,.yml, or.toml - Incremental builds — Cacheable task, skipped when inputs unchanged