Hi, I'm new to kotlin multiplatform and don't real...
# multiplatform
k
Hi, I'm new to kotlin multiplatform and don't really understand how to share code without creating dependency hell. I'm currently working on a volunteer project that uses kotlin multiplatform and we're starting from scratch. So I'd like to know how to organise the project structure (folders/modules) in a better way to stick to Clean Arch, the target platform is android, but I also want to support iOs, js, desktop, and most importantly server. Also, I want to share only the domain and data layers, not the UI. Can I use KMP Library Wizard as a starting point? if I'm not going to share UI between platforms, then I don't need the composeApp folder? And store UI + launcher for each platform on the same level as the shared module?
t
If you are writing only data models I think
commonMain
is enough and there is no need for dependencies. You need targets, those are quite straightforward.
commonMain
is compiled to all targets you specify. So if you have all the targets you listed you'll get a library for all those. You will need to add the android library plugin.
👀 1
k
I mean, do I really need the composeApp module with commonMain inside? Or can I remove that and then customize the module for each platform on the same level as shared and server?
t
Keep in mind that the wizard just gives you a very general template to work with, you can change almost everything. If you want to build an Android client I would say keep
composeApp
, keep things separated from the shared code. If you just want a server and some libraries you can drop
composeApp
,
server
and
iosApp
and put everything into
shared
. You can even promote
shared
into a main project without a surrounding outer project. It is really worth to check out the multiplatform documentation about how the directories are organized.
2
🙌 1