Hello! Why does creating a blank new Compose Multi...
# compose
b
Hello! Why does creating a blank new Compose Multiplatform project create 2 different modules for the JVM target. There is the desktop.jvmMain module and the common.desktopMain module, and I fail to understand what is the difference between those 2. In fact I think IntelliJ is as confused as I am because if you select "Compose Desktop Module" instead of "Console Application" in common > desktop when creating a new project, then the code from desktop.jvmMain does not even work (it does not compile .. but is never run anyway)
s
jvmMain includes JDK/java stuff, commonMain is intended to contain only pure kotlin this split let’s you add e.g. androidMain/jsMain and consume this common code from other platforms like web or mobile
you can also use multiplatform libraries in commonMain, so you are able to have logic like networking/caching that works in all the platforms, not just sharing some data classes
b
The thing is it generated an
actual fun getPlatformName()
function in
desktop.jvmMain
, but it does not compile:
"Actual function 'getPlatformName' has no corresponding expected declaration"
If I delete this function, then when I run
./gradlew run
it run the main function from
common.desktopMain
and then when I close the window it run the main function from
desktop.jvmMain
I think I get the idea but this behavior totally confused me.
s
You should have
expect getPlatformName()
in commonJvm then
b
Yes I have the
expect
in common.commonMain and its platform specific implementations using
actual
keyword in common.androidMain, common.desktopMain and desktop.jvmMain
That's how it was generated by the project template
I think I will generate a new project and see how it go, I haven't made much modifications to this one anyway
c
I'd ask in #compose-desktop maybe?