Skip to content

feat: Add KMP Product Flavors support#130

Closed
therajanmaurya wants to merge 1 commit intodevfrom
feature/kmp-product-flavors-integration
Closed

feat: Add KMP Product Flavors support#130
therajanmaurya wants to merge 1 commit intodevfrom
feature/kmp-product-flavors-integration

Conversation

@therajanmaurya
Copy link
Member

@therajanmaurya therajanmaurya commented Feb 25, 2026

Summary

Integrate kmp-product-flavors (v1.0.0) for cross-platform flavor support that aligns with existing Android application flavors.

Changes

  • Add kmp-product-flavors v1.0.0 to version catalog
  • Create KMPFlavorsConventionPlugin for easy integration
  • Add KmpFlavors.kt with centralized flavor configuration
  • Configure demo/prod flavors matching Android application
  • Add mavenLocal() for local development support

Features

  • Cross-platform flavor support - Same flavor configuration across Android, iOS, Desktop, and Web
  • BuildConfig generation - Flavor-specific constants accessible from shared code
  • Automatic source set wiring - commonDemo, commonProd, iosDemo, etc.
  • Aligned with Android - Uses same contentType dimension (demo/prod)

Usage

Apply to any KMP module:

plugins {
    id("org.convention.kmp.flavors")
}

Build with specific flavor:

./gradlew build -PkmpFlavor=prod
./gradlew build -PkmpFlavor=demo

List available variants:

./gradlew listFlavors

Generated BuildConfig

// Access from shared code
object FlavorConfig {
    const val VARIANT_NAME: String = "demo"
    const val IS_DEMO: Boolean = true
    const val IS_PROD: Boolean = false
    const val BASE_URL: String = "https://demo-api.mifos.org"
    const val ANALYTICS_ENABLED: Boolean = false
}

Test plan

  • Build project with ./gradlew build -PkmpFlavor=demo
  • Build project with ./gradlew build -PkmpFlavor=prod
  • Run ./gradlew listFlavors to verify variant configuration
  • Verify BuildConfig is generated in shared modules

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Added Kotlin Multiplatform Product Flavors support for cross-platform builds
    • Introduced DEMO and PROD flavor variants with environment-specific configurations
    • Enabled flavor-specific build configuration including base URLs and analytics toggles

Integrate kmp-product-flavors (v1.0.0) for cross-platform flavor support that aligns with existing Android application flavors.

## Changes
- Add kmp-product-flavors v1.0.0 to version catalog
- Create KMPFlavorsConventionPlugin for easy integration
- Add KmpFlavors.kt with centralized flavor configuration
- Configure demo/prod flavors matching Android application
- Add mavenLocal() for local development support

## Features
- Cross-platform flavor support (Android, iOS, Desktop, Web)
- BuildConfig generation with flavor-specific constants
- Automatic source set wiring for all platforms
- Aligns with existing Android contentType dimension (demo/prod)

## Usage
Apply to any KMP module:
```kotlin
plugins {
    id("org.convention.kmp.flavors")
}
```

Build with specific flavor:
```bash
./gradlew build -PkmpFlavor=prod
```

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@therajanmaurya
Copy link
Member Author

Update Needed Before Merge

The mavenLocal() repositories should be removed from:

  • settings.gradle.kts (pluginManagement and dependencyResolutionManagement)
  • build-logic/settings.gradle.kts

Since kmp-product-flavors v1.0.0 is now published to Maven Central and Gradle Plugin Portal, production applications don't need mavenLocal fallback.

I attempted to push this fix but the branch protection rules prevented it. Please remove these lines before merging:

- mavenLocal() // For local development with kmp-product-flavors

Library published to:

@therajanmaurya
Copy link
Member Author

Superseded by new PR with complete convention plugin integration

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4a85c9 and b2364ec.

📒 Files selected for processing (6)
  • build-logic/convention/build.gradle.kts
  • build-logic/convention/src/main/kotlin/KMPFlavorsConventionPlugin.kt
  • build-logic/convention/src/main/kotlin/org/convention/KmpFlavors.kt
  • build-logic/settings.gradle.kts
  • gradle/libs.versions.toml
  • settings.gradle.kts

📝 Walkthrough

Walkthrough

Introduces KMP Product Flavors support by creating a new Gradle convention plugin (KMPFlavorsConventionPlugin) that configures cross-platform flavor dimensions and flavors with build config generation, alongside flavor configuration infrastructure and repository setup for local development.

Changes

Cohort / File(s) Summary
Gradle Plugin Registration
build-logic/convention/build.gradle.kts
Added implementation dependency for KMP Product Flavors plugin and registered new kmpFlavors convention plugin with id org.convention.kmp.flavors.
Flavor Configuration Infrastructure
build-logic/convention/src/main/kotlin/org/convention/KmpFlavors.kt
Introduced KmpFlavors object defining flavor dimensions (CONTENT_TYPE) and flavors (DEMO, PROD) with data classes for dimension and flavor configuration, plus extension function configureKmpFlavors to apply flavors to KMP extensions with build config field support.
Convention Plugin Implementation
build-logic/convention/src/main/kotlin/KMPFlavorsConventionPlugin.kt
Created new KMPFlavorsConventionPlugin that applies KMP flavors plugin and configures dimensions/flavors using centralized configuration, including helper function to infer BuildConfig package names.
Version Catalog
gradle/libs.versions.toml
Added version entry for kmpProductFlavors (1.0.0) and library reference for KMP flavors Gradle plugin.
Repository Configuration
build-logic/settings.gradle.kts, settings.gradle.kts
Added mavenLocal() repository to plugin and dependency resolution management in both build-logic and root settings files for local development support.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 ✨ Flavors now bloom across platforms wide,
Build configs dance with DEMO and PROD pride,
Convention plugins hop with grace so fine,
KMP dimensions and build fields align—
Cross-platform harmony, a developer's delight! 🎉

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/kmp-product-flavors-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant