Hey all, is it possible to use “compose resources”...
# compose-desktop
k
Hey all, is it possible to use “compose resources” in a compose desktop only application - ie NOT a multi-platform project just a desktop project?
z
Hi, yes, you can use Compose Multiplatform resources even if you're running just one platform.
☝️ 1
The only limitation is that you need to put the resources under
commonMain
as of 1.6.0, but you'll be able to put them under other source sets like
desktopMain
once 1.6.10 comes out
k
Thanks. So the next question is, how do I set this up. I’ve tried adding a commonMain sourceset and then followed the instructions here (https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#setup) to add the dependency but compose.components is not available so it looks like I’m missing a setup step. My kts file looks like this
Copy code
sourceSets {
    create("commonMain") {
        kotlin.srcDirs("src/commonMain")
    }
}

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.components.resources)
            }
        }
    }
}
I’m using Compose 1.6.2
z
Generating a new project with Desktop-only on the KMP Wizard actually showcases a basic config for this, even includes a drawable as an example. This is what's generated there:
Copy code
kotlin {
    jvm("desktop")
    
    sourceSets {
        val desktopMain by getting
        
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
        }
        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
        }
    }
}
k
Thanks, I wasn’t using the KMP plugin, which I think is the secret sauce. It also means I had to rejig all my Gradle files as they were using the Kotlin plugin explicitly and it looks like the Kotlin plugin is pulled in by the KMP plugin
z
Ah yes, the KMP plugin is a good choice even if you're targeting just one platform for the time being, as then anything you find for KMP will apply directly to your project
100 Views