I think there was a feature added some time ago th...
# multiplatform
a
I think there was a feature added some time ago that allows multiple JVM targets, such as Android and Desktop. to share a common JVM source set so you dont have to duplicate common code between them. What was that called? Any links to how to enable/use it?
a
ah yup, this looks like it, thanks!
this is exactly what i'm looking for, but for JVM targets, looks like I can do it manually, would be cool to get built in support in the future like the ios targets
j
Kotlin doesn't currently support sharing a source set for these combinations:
• Several JVM targets
• JVM + Android targets
• Several JS targets
^ from the manual configuration section linked above I think this means that while you can share code between JVM and Android platforms, the "common" module between them doesn't support JVM-specific features and will only work with things in Kotlin's common library. I'm not sure about the details.
Although you can probably still share code with a library in the old fashioned way. Basically create another project to dump the shared JVM+Android code into, and make both JVM and Android targets use it as a dependency in your multiplatform project.
a
ya
doesnt look like it will work for me in its current state
what i really want is how the ios hierarchy works
j
You can still share source folders to eliminate duplication
j
I have a shared jvm + android intermediate source set in my library, but yes there are some rough edges. There isn't any commonization for dependency APIs used in the edge source sets, like there is for native targets. Generally it's good enough to just use the jvm edge's dependencies in the common JVM intermediate source set, but it doesn't do this for you, so the IDE can't see any dependency code in the shared source set. I've worked around this by adding the jvm edge's dependency as
compileOnly
in the common JVM source set, and then add again as `implementation`/`api` in the jvm edge. This mostly works, except that the android source set may possibly prioritize the JVM dependency over its Android-specific dependency, resulting in IDE errors if there are similar but differing APIs between jvm and android. @Sebastian Sellmair [JB] was looking for valid use cases for this, if you want to share more about your specific requirements. https://kotlinlang.slack.com/archives/C3PQML5NU/p1661339694375649?thread_ts=1661339694.375649&cid=C3PQML5NU
a
ah yup, that's exactly what I was looking for, thumbed it up 🤞