Multiplatform and mulitple jvm targets


#1

We have a library to be shared between jvm(server) and jvm(android). It is to move to multi-platform because services like http can vary between these platforms.

It seems ‘import java.???’ is simply not possible in common. This makes sense for many calls, as these will involve calls to the jvm platform itself. However I would have thought some calls in things like java.lang.math would simply produce inline code, but if I have it correctly, I would it seems nothing can be imported from java?

This brings to the main question, with code that is common between two platforms, is there a standard or recommended way to share code between two platforms? I was thinking of a source folder added to the source folders for both projects, but perhaps there is a better way?


#2

Your problem is not strictly related to Kotlin, you should deal with it same as a Java problem.
You can use a multi-release JAR, as example, or deploy two versions with same interfaces.

What solution wish you take in a Java project?


#3

Consider using the Ktor HTTP multiplatform client.


#4

What you want is actually possible, but tricky. All the java types need to be made available through expect and “implemented” through a typealias. This can even be done in a source set that is actually shared by both android and java (I don’t know what happens if this sourceset is also the one with the expect). This shared source, while built correctly by gradle, will not be recognised by intellij as “jvm” based and will not get the standard library in its path.


#5

May be what you want to do is something similar to this: