Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting in gradle.properties is ignored #180

Open
JaFiOriflame opened this issue Dec 18, 2024 · 2 comments
Open

Setting in gradle.properties is ignored #180

JaFiOriflame opened this issue Dec 18, 2024 · 2 comments
Labels
contribution welcome help wanted Extra attention is needed

Comments

@JaFiOriflame
Copy link

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
@JaFiOriflame
Copy link
Author

Any idea?

@yshrsmz yshrsmz added help wanted Extra attention is needed contribution welcome labels Jan 6, 2025
@RyuNen344
Copy link
Collaborator

@JaFiOriflame
maybe you want to do like this?

targetConfigs("uat") {
    // some configs
}
targetConfigs("stg") {
    // some configs
}
targetConfigs("prod") {
    // some configs
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants