Skip to content

Setting in gradle.properties is ignored #180

@JaFiOriflame

Description

@JaFiOriflame

Describe the bug
I have compose multiplatform project with multiple modules. I applied all the steps described in the README.md to use flavors. However, the setting in gradle.properties is ignored. I still obtain defaultConfigs values :-( I suppose it is my bug, but I'm not able to find that.

/composeApp/build.gradle.kts

import com.oriflame.business.Modules
import com.oriflame.business.Versions
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.composeCompiler)

    alias(libs.plugins.com.oriflame.business.plugin.detekt)

    alias(libs.plugins.kotlinSerialization)

    alias(libs.plugins.buildKonfig)
}

kotlin {
    androidTarget {
        @OptIn(ExperimentalKotlinGradlePluginApi::class)
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_11)
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
        }
    }
    
    sourceSets {
        
        androidMain.dependencies {
            implementation(compose.preview)
            implementation(libs.androidx.activity.compose)

            // Koin
            implementation(libs.koin.android)
            implementation(libs.koin.androidx.compose)
        }
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material3)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
            implementation(libs.androidx.lifecycle.viewmodel)
            implementation(libs.androidx.lifecycle.runtime.compose)

            implementation(project(Modules.localizations))
            implementation(project(Modules.commonData))
            implementation(project(Modules.commonDomain))
            implementation(project(Modules.commonRepositories))
            implementation(project(Modules.commonInfrastructure))

            implementation(project(Modules.featureEmpty))
            implementation(project(Modules.featureWelcome))

            // Koin
            api(project.libs.koin.core)
            implementation(libs.koin.compose)
            implementation(libs.koin.compose.viewmodel)

            // KotlinX Serialization
            implementation(libs.kotlinx.serialization.json)

            // Navigation
            implementation(libs.navigation.compose)
        }
    }
}

android {
    namespace = "com.oriflame.business"
    compileSdk = Versions.COMPILE_SDK

    defaultConfig {
        applicationId = Versions.App.ID
        minSdk = Versions.MIN_SDK
        targetSdk = Versions.TARGET_SDK
        versionCode = Versions.App.VERSION_CODE
        versionName = Versions.App.VERSION_NAME
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
    compileOptions {
        sourceCompatibility = Versions.JAVA_VERSION
        targetCompatibility = Versions.JAVA_VERSION
    }
}

dependencies {
    debugImplementation(compose.uiTooling)
}

buildkonfig {
    packageName = "com.oriflame.business"
    exposeObjectWithName = "BuildKonfig"

    val envPropertyName = "env"
    val suffixPropertyName = "suffix"
    val appLabelPropertyName = "appLabel"

    defaultConfigs {
        // Default to UAT if not specified
        buildConfigField(STRING, envPropertyName, "test")
        buildConfigField(STRING, suffixPropertyName, "test")
        buildConfigField(STRING, appLabelPropertyName, "test")
    }

    targetConfigs {
        create("uat") {
            buildConfigField(STRING, envPropertyName, "uat")
            buildConfigField(STRING, suffixPropertyName, "uat")
            buildConfigField(STRING, appLabelPropertyName, "AppName (UAT)")
        }
        create("stg") {
            buildConfigField(STRING, envPropertyName, "stg")
            buildConfigField(STRING, suffixPropertyName, "stg")
            buildConfigField(STRING, appLabelPropertyName, "AppName (STG)")
        }
        create("prod") {
            buildConfigField(STRING, envPropertyName, "prod")
            buildConfigField(STRING, suffixPropertyName, "")
            buildConfigField(STRING, appLabelPropertyName, "AppName")
        }
    }
}

/gradle.properties

#Kotlin
kotlin.code.style=official
kotlin.daemon.jvmargs=-Xmx2048M

#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8

#Android
android.nonTransitiveRClass=true
android.useAndroidX=true

buildkonfig.flavor=stg

I print the values into the log in my app:

...
Log.d("HERE env: " + BuildKonfig.env)
Log.d("HERE suffix: " + BuildKonfig.suffix)
Log.d("HERE appLabel: " + BuildKonfig.appLabel)
...

I still obtain this:

HERE env: test
HERE suffix: test
HERE appLabel: test

/gradle/libs.versions.toml

[versions]
...
# BuildKonfig
buildKonfig = "0.15.2"

[plugins]
...
# BuildKonfig
buildKonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildKonfig" }

Do you see where could be the problem?

I also tried to compile and run the app from command line and the same result:

./gradlew assembleDebug -Pbuildkonfig.flavor=stg
./gradlew installDebug 

To Reproduce
Don't have repo

Expected behavior
I would expect that setting in gradle.properties or in command line will be taken into consideration.

Screenshots
None.

Desktop (please complete the following information):

  • OS: Mac Sequoia 15.1.1
  • BuildKonfig Version: 0.15.2
  • Kotlin Version: 2.0.21
  • AGP Version: 8.5.2
  • Gradle Version: 8.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    contribution welcomeThe team would welcome a contribution from the community for this issuehelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions