Hi guys! I wanted to discuss this topic: <https://...
# multiplatform
h
Hi guys! I wanted to discuss this topic: https://youtrack.jetbrains.com/issue/KT-30878 I wanted to write a small library that would contain some business logic which should be shared across a service, an Android app and an iOS app. I can compile it separately for Java and Android, but I’m struggling to find the best way to structure the project in such a way that would allow me to build 3 different artifacts from the same code base. Has anyone had to solve a similar problem?
j
why you need the java plugin?
u
This works for me:
Copy code
kotlin {
    android()
    jvm("desktop")
}
👍 2
j
but I am not sure what he wants to achieve, because kmp generate by default a jvm, android an ios artifacts, but maybe he can publish it with different groups or names?
h
Thanks for your feedback guys! @Javier it’s a good question indeed. I have a JSON file that needs to be distributed with the library and since I started with JVM first, I put the file into
resources
and used
java.getResource()
to read it.
@uli thanks, it did solve the build problem 🙂
👍 1
j
you can put it in commonMain/resources
h
That’s what I did, yes. Unfortunately, it doesn’t quite work, so I must be missing something in a different place. I’ve added this test to the `commonTest`:
Copy code
@Test
fun testConfigIsPresent() {
    val cfg = ConfigTest::class.java.getResource("/cfg.json")
    assertNotNull(cfg)
}
and it fails. I have this entry in `build.gradle.kts`:
Copy code
val commonTest by getting {
    dependencies {
        implementation(kotlin("test"))
       }
    }
u
commonTest is not JVM specific though
j
exactly
have you tried okio to load the file?
h
I see, then it explains it 🙂 @Javier no, I’m very new to both Kotlin and mobile dev and didn’t know about that library. Thanks once more for your help! 🙂
u
Take a look here for fine grained build script: https://gitlab.com/uluckas/s2-CrossPlatform-Test/-/blob/master/shared/build.gradle.kts It requires
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
in
gradle.properties
👍 1
it comes with android, desktop, ios, common to share for all platforms and especially commonJvm to share between android and jvm