Is it possible to consume a pure kotlin dependency...
# multiplatform
u
Is it possible to consume a pure kotlin dependency in a multiplatform module?
Copy code
val commonMain by getting {
    dependencies {
        api(project(":some-pure-kotlin-stuff"))
    }
}
gives me odd errors at sync time
Copy code
:shared:iosArm64Main: Could not resolve project :some-pure-kotlin-stuff
Required by:
    project :shared

Possible solution:
 - Declare repository providing the artifact, see the documentation at <https://docs.gradle.org/current/userguide/declaring_repositories.html>
Is this not supported? Can KMP modules only depend on KMP modules?
m
The dependency must support the targets which you have enabled in your module. From the looks of your error, the "pure kotlin" dependency does not support the
iosArm64
target and cannot provide the
.klib
for it.
u
I don't follow, the pure kotlin dependency is just a
Copy code
plugins {
    id "kotlin"
}
and nothing extra. Should that not just work?
m
use
kotlin("multiplatform")
u
is that the only way? to make the pure kotlin multiplatform aware? I thought if there is no jvm/android dependency anywhere, it can be consumed directly
m
👀 I'm not sure of that... Would be nice.
r
At the moment there's no such thing as a "pure Kotlin" module the way you seem to be expecting. Multiplatform modules must declare their targets, and can only depend on modules that include the same targets. Using
id "kotlin"
isn't pure Kotlin, it's actually JVM. You need to use the multiplatform gradle plugin for multiplatform.
u
I see, so
id "kotlin"
is essentially equivalent to
Copy code
plugins {
    id "org.jetbrains.kotlin.multiplatform"
}

kotlin {
    jvm()
}
?
j
no it's an alias for
org.jetbrains.kotlin.jvm
it behaves similarly to what you wrote, but not strictly the same
u
I see, I somehow thought the final app can dictate the target platform, but yea that's nonsense, "id kotlin" is jvm, invokes kotlinc, which produces jvm bytecode etc
j
What you are referring to is IR-only dependencies which are still a long way away. This will allow you to ship target-agnostic Kotlin which is lowered to the specific platforms you are targeting as part of your compilation step. It's also not 100% bulletproof, as a new target may be incompatible with the APIs you reference.
u
is that dependant on the K2 coming online?
j
It depends on a stable, serializable IR format. I don't think that's strictly tied to K2, but they certainly will do K2 before doing this.
u
I see, that would be sweet, although, gradle folks recommend the convention plugins anways, so hiding the setup shouldn't be that hard
r
https://youtrack.jetbrains.com/issue/KT-52666 if you want to follow progress
u
so in a "pure" kotlin module (lets just say some business logic, no platform dependencies, just kotlin sdtlib)
Copy code
plugins {
    id "org.jetbrains.kotlin.multiplatform"
}

kotlin {
    jvm()
    ios()
}
is the minimum config needed to get android and ios apps going?
j
ios()
does not include the arm simulator, but otherwise yes. also you may want
android()
and not
jvm()
depending on whether you use Android APIs or not.
u
when setting up our project some time ago, I was peripherally aware of kotlin multiplatform, hoping it would mature, and came up with internal rule to have pure jvm kotlin modules whenever practical, which is turns out most of the app, and naively I think this makes built times faster 😄
j
it absolutely does
a pure JVM module will run like three tasks to build. an Android one runs like 100.
u
okay so the MO should be jvm+ios(+simulator), and we can sort of pretend it's a IR-only dependency in
/commonMain
r
well, until you decide you want to add browser support 🙂
u
as in JS?
r
yeah, or wasm eventually
I wouldn't worry too much about that though if it's not already on your roadmap. It's impossible to future-proof everything
u
we have a monorepo, adding it should be trivial, given the internal convention plugin
thank you all, very enlightening!
to clarify, by spraying
Copy code
plugins {
    id "org.jetbrains.kotlin.multiplatform"
}

kotlin {
    jvm()
    ios()
}
everywhere, I will double my
assemble
time, right?