I’m targeting android, ios, and backend (jvm/ktor)...
# multiplatform
j
I’m targeting android, ios, and backend (jvm/ktor) in my project. I’m sharing models for all those targets but I want to share the code for the api client only between android and ios. Is there a way to tell gradle to not care about missing dependencies for
ktor-client
under my
sourceSets["backendMain"].dependencies
?
b
You can make use of granular sourcesets
Create clientCommon sourceSet that depends on common and hook it up to client platrofms
Put all client specific code there
r
Alternatively, you could have two separate gradle modules. One for code shared between all platforms, and another that's just shared between clients.
j
So I decided to go with @Big Chungus suggestions. I created
clientCommon
source set and made android and ios target depends on it. Thanks for the help 🙂
g
I think using own module is better solution than source set
j
what are the benefits of a separate gradle module?
b
Just stricter isolation. But mostly I think the choice here comes down to preference
👌 1
g
isolation yes, also you may have custom build config, flags, dependencies etc for this module, source set works, but I think it’s more limited thing
b
Probably worth mentioning that sourceSet enables expect/actual feature, whereas you cannot do that with modules
g
Isn’t it’s the same for modules, you need a module with full set of APIs, so you have Kotlin MPP module with required expect/actual declarations for target platforms
b
Exactly what i was trying to say 😀
g
but you may have expect/actual with modules
on level of module
b
i meant you can't have expect on module A and actual on module B
g
sure
and it sounds like a good thing
b
It is, just saying that depending on the use-case, modules might not be suitable. e.g. if you have some ambiguous code that you want to be shared between all platforms, but they all have slightly different implementations