Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started

Installation

Add to your gradle/libs.versions.toml:

[versions]
kenvConfig = "0.2.0"

[plugins]
kenvConfig = { id = "io.github.adventures92.kenv-config", version.ref = "kenvConfig" }

Then in your module’s build.gradle.kts:

plugins {
    alias(libs.plugins.kenvConfig)
}

Option 2: Direct Plugin Application

In your module’s build.gradle.kts:

plugins {
    id("io.github.adventures92.kenv-config") version "0.2.0"
}

Repository Setup

Ensure mavenCentral() and gradlePluginPortal() are in your settings.gradle.kts:

pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
}

Project Setup

1. Create the kenv directory

Create a kenv/ directory in your module root:

my-app/
├── kenv/
│   ├── schema.kenv.yaml
│   ├── env.dev.env
│   ├── env.production.env
│   └── env.global.env
├── src/
└── build.gradle.kts

2. Define your schema

Create kenv/schema.kenv.yaml:

environments:
  - dev
  - production

variables:
  DEBUG_MODE:
    type: Boolean
    scope: environment
    description: "Enable debug logging"

groups:
  server:
    API_URL:
      type: Url
      scope: environment
      description: "Backend API base URL"
    API_PORT:
      type: Int
      scope: environment
      description: "Backend API port"
  app:
    APP_NAME:
      type: String
      scope: global
      description: "Application display name"

3. Create environment files

kenv/env.dev.env:

DEBUG_MODE=true
API_URL=http://localhost:8080
API_PORT=8080

kenv/env.production.env:

DEBUG_MODE=false
API_URL=https://api.myapp.com
API_PORT=443

kenv/env.global.env:

APP_NAME=My App

4. Configure the plugin

In your build.gradle.kts:

kenvConfig {
    directory.set(file("kenv"))
    environments.set(listOf("dev", "production"))
    generatedPackageName.set("com.example.config")
}

5. Generate and use

Run the generation task:

./gradlew kenvGenerate

Then use the generated code:

import com.example.config.EnvConfig

// Set active environment (KMP approach)
EnvConfig.setActiveEnvironment("dev")

// Access values with flat syntax
println(EnvConfig.Server.API_URL)       // "http://localhost:8080"
println(EnvConfig.Server.API_PORT)      // 8080
println(EnvConfig.DEBUG_MODE)           // true
println(EnvConfig.App.APP_NAME)         // "My App"

// Or access per-environment directly
println(EnvConfig.Production.Server.API_URL)  // "https://api.myapp.com"

Next Steps