Hey friends! This is a silly question, so apologie...
# multiplatform
p
Hey friends! This is a silly question, so apologies in advance. 😅 I have some tests in
commonTest
. Recently, I noticed that I inadvertedly used JVM-specific code in one of those tests (namely,
File
and
readText()
. Although the tests run without any issues, I think I should move them to
jvmTest
instead because it uses non-common code. Is this the correct way to go, or should I keep this scenario as-is? Thanks!
✔️ 1
j
That entirely depends on what targets you want to support. If it's only the JVM and Android, for example, then
File
is common to them. However, if you have any native, js, and/or wasm targets then that will fail compilation when you try to compile tests for those targets.
gratitude thank you 1
🔥 1
p
Thanks so much, @jw! That makes sense. Currently we are only targeting JVM, that's why it's working. I will make a note for my future self in case we expand the coverage to other targets. 😉
d
@Paulo Cereda FYI in the early days of KMP,
commonMain
was able only to access a fixed API that was the intersection of all supported targets. In recent Kotlin versions though,
commonMain
now sees a dynamically computed API - the intersection of all enabled targets. This makes
commonMain
more intelligent and flexible - allowing you to use
File
being a nice example.
gratitude thank you 1
🔥 1
🚀 1
j
Recent being like... the last 7 years though. It's been this way for the overwhelming majority of its existence.
Probably even longer, actually. I think my first real KMP experiment was late 2016 and it already behaved the the way it does today.
👍 1
👍🏾 1
d
I'm old
m
Another possibility would be to just replace
File
and
readText()
by their corresponding counterparts from a multi-platform IO library like Okio or kotlinx-io. Then you’d be ready for the future. There’s no point in using Java dependencies if they can be easily avoided. Of course that’s not always the case.
gratitude thank you 1
p
Thanks for the suggestions, friends! gratitude thank you