https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

abbic

02/18/2023, 2:24 PM
this may be a silly question, but im confused about creating a multi-module application from the compose desktop starter project. i know how to add a module on android, but here it seems that the base module is top level. the jvmMain and jvmTest directories (i dont know whether to also consider them modules or not) dont have their own build.gradle file where i would add things like
implementation(path: ':common')
e

ephemient

02/18/2023, 7:47 PM
jvmMain and jvmTest are not modules, they are source sets
similar to how a pure Android project will have main, test, androidTest, debug, debugTest, debugAndroidTest, release, releaseTest… source sets
a

abbic

02/18/2023, 7:49 PM
ooh
fascinating
so then adding more seems like its only mostly relevant for multiple platforms?
e

ephemient

02/18/2023, 7:50 PM
if none of your code is platform-specific, then it would be expected that you only need commonMain and commonTest
a

abbic

02/18/2023, 7:51 PM
makes sense 👍 although this begs the question for me of how to actually implement modularisation in a project like this
as ive implied, i only know how to do anything of the sort when working on android projects. i dont even know what to google to get a primer on the matter
actually there's a question, what do i call this kind of desktop jvm development, in a way that will bring up relevant info on google?
e

ephemient

02/18/2023, 7:54 PM
it really isn't that different from Android's variants
in the Android world, by default you have
Copy code
:lib
    src/main
    src/debug
    src/release
:app
    src/main
    src/debug
    src/release
:lib
produces two variants,
debug
(which includes code from both
src/main
and
src/debug
) and
release
(which includes code from both
src/main
and
src/release
). in
:app
, code in
src/main
can use code in `:lib`'s
src/main
, code in
src/debug
can use code in `:lib`'s
src/main
and
src/debug
, and code in
src/release
can use code in `:lib`'s
src/main
and
src/release
. (there's some boundaries here that aren't as well enforced as KMP but that's basically the idea)
similarly, in your multiplatform setup, you can have
Copy code
:lib
    src/commonMain
    src/jvmMain
:app
    src/commonMain
    src/jvmMain
with the
jvm
platform containing code in both
src/commonMain
and
src/jvmMain
, and matching across module dependencies
within a single project (module) there are dependencies within source sets, but that doesn't matter outside of the project
a

abbic

02/18/2023, 8:02 PM
this tracks, the only issue im seeing from my end is that, directory wise, things are laid out like
Copy code
root-project
    :lib
        src/commonMain
        src/jvmMain
    :app
        src/commonMain
        src/jvmMain
this makes sense to me, but the default compose multiplatform project looks more like
Copy code
:root-project
    src/commonMain
    src/jvmMain
so the root build.gradle is bot a "root project" gradle file and a module one. and in IDEA, when you add another module it is created in parallel, like
Copy code
:root-project
    src/commonMain
    src/jvmMain
:module
    etc
e

ephemient

02/18/2023, 8:03 PM
so, you can create subprojects just fine even if there's code within the root project
a

abbic

02/18/2023, 8:03 PM
and they dont seem to link up together like how id expect
e

ephemient

02/18/2023, 8:04 PM
but if you want to modularize it, I would move things from the root project into a subproject
it works even if you don't, though.
a

abbic

02/18/2023, 8:04 PM
yes, thats the impression i was beginning to get from our discussion: just move things around until they look like how id expect. if i want to.
e

ephemient

02/18/2023, 8:04 PM
you'll just have
Copy code
:
    src/...
:lib
    src/...
a

abbic

02/18/2023, 8:04 PM
this is also my first project with kotlin gradle files, so its a bit of a double culture shock
nothing i cant handle though (i think :p) thanks for your help!
5 Views