What’s the best way to create a Desktop Compose ap...
# compose-desktop
s
What’s the best way to create a Desktop Compose application with the equivalent of Android Flavors? I’d like to have 2 variants of my application - Internal and Production, and I’d like to exclude certain code from being in the production variant, and enable certain testing functionality in my internal variant, like server selection, etc. I tried using multiple jvm targets with the multiplatform plugin, and created a
desktopMain
source set, but I couldn’t use jvm dependencies in it (It was looked at / viewed as a common source-set I think). What else could I try?
1
I just thought of dynamically adding sourcesets based on gradle build properties. I’m pretty confident this will work, and it will also play nicely with the gradle
application
plugin.
Copy code
kotlin {
    targets {
        jvm()
    }

    sourceSets {
        val commonMain by getting {
            if (project.hasProperty("buildProduction")) {
                kotlin.srcDir("src/production/kotlin")
            } else {
                kotlin.srcDir("src/internal/kotlin")
            }
I’m interested to know if anyone thinks of something better!
2
x
where do you set this property?
gradle.properties
?
s
You configure the property via
-P
for any gradle command. i.e. if I wanted to run in production, I’d just run
Copy code
./gradlew :app:run -PbuildProduction
x
cool - i guess this is not as convenient as AS built variants but should do in the interim till JB officially support built variants with MPP
111 Views