I've built a lib in Kotlin, which I would like to use in Kotlin backend, Android app & in swift ios app. Lib is written in plain Kotlin and it consists of 3 modules, dependent from each other. To create multiplatform/ios version of it, I've created separated module with build.gradle.kts:
plugins {
kotlin("multiplatform")
}
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation(project(":myJvmModule"))
}
}
}
iosArm64 { binaries.framework("NativeFramework") }
iosX64 { binaries.framework("NativeFramework") }
tasks {
...
}
}
tasks.withType<Wrapper> {
gradleVersion = "5.3.1"
distributionType = Wrapper.DistributionType.ALL
}
Besides that, myJvmModule has build.gradle.kts:
val fasterXmlVersion: String by project
plugins {
kotlin("jvm")
}
dependencies {
// Modules
implementation(project(":myAnotherModule"))
implementation(project(":myAnotherModule2"))
// Jackson
implementation(group = "com.fasterxml.jackson.module", name = "jackson-module-kotlin", version = fasterXmlVersion)
}
No matter how I try to use myJvmModule as dependency, I always receive error:
Could not resolve company:myJvmModule:0.0.1
How can I import JVM module to multiplatform module?
I'm not sure I completely understand your question here. If your intention is to use a JVM module transitively from a native module, it's simply not possible.
Multiplatform modules have different source sets: common, JVM, JS, and native ones like iOS.
In a multiplatform module, you can only depend on JVM modules from the JVM source set. But note that this dependency will only be available to the JVM "flavour" of the multiplatform library, not to the iOS one.
If you want to use a multiplatform library from a platform specific module like iOS, that "consumer" module will only have access to the common code and the iOS-specific code of the multiplatform library. Since it will be running on iOS, there is no way that module can transitively use a JVM one (it won't have a JVM runtime).
I guess your best option here (if you control the JVM module) is to turn your JVM module into a multiplatform one as well. Any JVM library used there will need to be replaced by a multiplatform equivalent, or a native equivalent will need to be added for the native target. If you choose the latter, you'll likely have to define a common API in common code, and use expect
/actual
declarations to map common code to platform-specific one.
You can read more about multiplatform dependency management in the official doc.