https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jean

07/29/2020, 1:20 PM
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

Big Chungus

07/29/2020, 1:24 PM
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

russhwolf

07/29/2020, 1:40 PM
Alternatively, you could have two separate gradle modules. One for code shared between all platforms, and another that's just shared between clients.
j

jean

07/29/2020, 2:01 PM
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

gildor

07/30/2020, 6:47 AM
I think using own module is better solution than source set
j

jean

07/30/2020, 7:02 AM
what are the benefits of a separate gradle module?
b

Big Chungus

07/30/2020, 7:13 AM
Just stricter isolation. But mostly I think the choice here comes down to preference
👌 1
g

gildor

07/30/2020, 8:06 AM
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

Big Chungus

07/30/2020, 9:21 AM
Probably worth mentioning that sourceSet enables expect/actual feature, whereas you cannot do that with modules
g

gildor

07/30/2020, 9:24 AM
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

Big Chungus

07/30/2020, 9:41 AM
Exactly what i was trying to say 😀
g

gildor

07/30/2020, 9:44 AM
but you may have expect/actual with modules
on level of module
b

Big Chungus

07/30/2020, 9:44 AM
i meant you can't have expect on module A and actual on module B
g

gildor

07/30/2020, 9:45 AM
sure
and it sounds like a good thing
b

Big Chungus

07/30/2020, 9:47 AM
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
4 Views