Quick start
1. Add your config
Section titled “1. Add your config”Save the default JSON config as default.json:
{ "flavors": { "prod": { "api_base_url": "https://api.example.com", "feature_search_enabled": false }, "dev": { "api_base_url": "https://dev.example.com", "feature_search_enabled": true } }, "brand_name": "Example App"}YAML works with the same shape:
flavors: prod: api_base_url: https://api.example.com feature_search_enabled: false dev: api_base_url: https://dev.example.com feature_search_enabled: truebrand_name: Example AppIf you use YAML, save the file as default.yml or default.yaml and set
configFormat in the Gradle block below.
2. Apply the plugin and declare schema
Section titled “2. Apply the plugin and declare schema”plugins { // Use any supported Kotlin plugin: // kotlin("multiplatform"), kotlin("jvm"), or kotlin("android") kotlin("multiplatform") version "<kotlin-version>" id("io.github.mohamadjaara.kayan") version "<kayan-version>"}
kayan { packageName.set("sample.generated") className.set("SampleConfig") flavor.set("prod")
// Keep the default for default.json, or use YAML explicitly: // baseConfigFile.set(layout.projectDirectory.file("default.yml")) // configFormat.set(io.kayan.ConfigFormat.YAML)
schema { string("api_base_url", "API_BASE_URL", required = true) boolean("feature_search_enabled", "FEATURE_SEARCH_ENABLED") string("brand_name", "BRAND_NAME") }}3. Build to generate
Section titled “3. Build to generate”./gradlew generateKayanConfigKayan writes the generated source to build/generated/kayan/kotlin and adds that
directory to commonMain for KMP or main for JVM and Android.
4. Use generated values
Section titled “4. Use generated values”import sample.generated.SampleConfig
val baseUrl = SampleConfig.API_BASE_URLval search = SampleConfig.FEATURE_SEARCH_ENABLEDval brand = SampleConfig.BRAND_NAME