Is it possible to have a shared sourceset for Jvm(...
# multiplatform
m
Is it possible to have a shared sourceset for Jvm(Desktop) + Android? as per Kotlin documentation: > Kotlin doesn't currently support sharing a source set for these combinations: > • Several JVM targets > • JVM + Android targets > • Several JS targets There is no official solution, but I'm wondering if there is a workaround/hack I can use, I looked at the official samples/templates and other multiplatform projects but couldn't find a solution.
j
It is possible. In general it should work, but it might depend what your dependencies are and how you're sharing code, what APIs you're using in the shared source set. In some cases you might need workarounds, as there isn't a commonizer, like Kotlin/Native source sets have. I have a jvmCommon source set in my library.
m
I'm not targeting Kotlin/Native currently, Mainly I wanted a shared source set between Jvm + Android to avoid duplicate
actual
implementations like using Okhttp for example as an http client. Anyway, thanks for the repo, will try it out and see if it works
j
If you're only accessing Java and Kotlin APIs that are common between JVM and Android targets, or dependencies with a common artifact, it should work just fine.
e
if you don't have any Android-specific code or dependencies, try just using a single JVM source set. Android consumers can use JVM libraries
👆🏼 1
👆🏾 1
j
Yes, a shared JVM + Android source set only makes sense if you also have the need for at least some code in the android or jvm source sets, or an Android-specific dependency, that requires an Android-specific build.
m
@ephemient Yeah, this is a good approach but, Unfortunately I have a few android specific dependencies So, I'am using Jeff's setup and it works well so far.
e
IntelliJ had some issues with that setup in the past, but it should generally work now AFAIK
m
I was worried about that but after I tried it, I didn't get any IDE errors