Skip to content

Moes81/BuildConfigReproducer

Repository files navigation

CoffeeMate — KMP / BuildKonfig Workshop Starter

A deliberately minimal Kotlin Multiplatform + Compose Multiplatform app (Android, iOS, Desktop). The app is just a stage for build-time configuration: a coffee-ordering screen with a debug strip at the bottom that prints every config value on screen. Your job in the workshop is to replace the hardcoded AppConfig with a generated one from BuildKonfig and watch those values change per build flavor.

The screen reads all config (top-bar title, prices, debug strip) from a single AppConfig object, so once it's BuildKonfig-generated the UI updates with no UI code changes.

Note: the Gradle project is still named ConfigurationManagement (unchanged on purpose). The visible app title comes from AppConfig.APP_NAME and shows "CoffeeMate (DEV)".

Requirements

  • JDK 17+ (required for the Desktop target / packaging; JDK 11 is the language level).
  • Android Studio or IntelliJ IDEA with the Kotlin Multiplatform plugin.
  • Xcode 15+ (only for the iOS target).
  • Kotlin 2.4.0 · Compose Multiplatform 1.11.1 · AGP 9.2.1 — all pinned in gradle/libs.versions.toml.

Running

Desktop is the fastest feedback loop — use it during the workshop:

# Desktop (JVM) — recommended
./gradlew :desktopApp:run

# Desktop with hot reload
./gradlew :desktopApp:hotRun --auto

# Android (install on a running emulator/device)
./gradlew :androidApp:assembleDebug
./gradlew :androidApp:installDebug

# iOS — open the Xcode project and Run
open iosApp/iosApp.xcodeproj

The shared UI/logic lives in :shared and is consumed by every platform entry point, so a change in shared shows up on all targets.

Where the code lives

File (shared/src/...) Purpose
commonMain/.../AppConfig.kt The hardcoded config — the thing you replace with BuildKonfig.
commonMain/.../CoffeeMenu.kt Coffee menu data + formatPrice() (reads AppConfig.CURRENCY).
commonMain/.../PaymentProvider.kt Interface + expect getPaymentProvider().
<target>Main/.../PaymentProvider.<target>.kt Per-platform actual (currently all "GenericPay").
commonMain/.../App.kt The Compose screen + the DebugStrip that prints all config.

PARTICIPANT TODOs

Every spot you need to touch is marked with a // TODO(workshop): comment. Do them in order:

  1. Apply the BuildKonfig plugin. In shared/build.gradle.kts, add alias(libs.plugins.buildkonfig) to the plugins { } block. The version is already pinned in gradle/libs.versions.toml (buildkonfig = "0.21.2", plugin id com.codingfeline.buildkonfig) — do not change versions.

  2. Configure the buildkonfig { } block in shared/build.gradle.kts:

    • packageName = "com.mw.mdp.configmanagement"
    • In defaultConfigs { }, declare the five fields currently in AppConfig: ENVIRONMENT, API_URL, APP_NAME (String), CURRENCY (String), ANALYTICS_ENABLED (Boolean). Use buildConfigField(STRING, "API_URL", "http://localhost:8080"), etc.
    • Give the object the same name with objectName = "AppConfig".
  3. Delete commonMain/.../AppConfig.kt and rebuild. The generated AppConfig takes its place; the UI keeps compiling because the field names match.

  4. Add build flavors (e.g. dev vs prod). Use targetConfigs/flavor overrides so prod gets ENVIRONMENT = "prod", a real API_URL, APP_NAME = "CoffeeMate", CURRENCY = "EUR", ANALYTICS_ENABLED = true. Switch flavor via the buildkonfig.flavor Gradle property and watch the debug strip and prices change on screen.

  5. Source-set override (PaymentProvider). Replace the platform actual getPaymentProvider() implementations so each region returns its own provider name (e.g. GooglePay on Android, ApplePay on iOS). The "Payment provider" line in the debug strip updates per target — no common code changes.

Re-run ./gradlew :desktopApp:run after each step to see the effect immediately.

About

A Reproducer for gradle-buildconfig-plugin Issue #394

Resources

Stars

Watchers

Forks

Contributors