When I plan to have a pure kotlin library but for ...
# multiplatform
l
When I plan to have a pure kotlin library but for now only want to support jvm target, should I create a kotlin JVM library or a mmp library? Is there any difference between jvm and mmp library if I would define only jvm target in mmp library?
c
If you are planning on reusing this code on different platforms in the future, you can start by setting up a kmp library from the beginning. I personally try to take this approach and it has helped to keep most of my projects multiplatform ready.
But there is the caveat that the kmp plugin is still in alpha stage and things sometimes break. That has been my biggest drawbacks. So if you only need a JVM target, just using the jvm kotlin plugin may be better.
l
ok so the only difference is to be kmp ready in advance? Just of curiosity: when I go with jvm library...could I later upgrade to kmp by replacing the jvm plugin with the kmp plugin or would it be better to create a new project with kmp support? I would also have to define targets and create the source set folder manually, but that's all or did I miss something?
c
Yes you can always easily upgrade later.
u
And be aware that if you start with the java plugin you will not notice if you accidentally depend on JVM features and Android Studio will even auto complete java classes.
⚠️ 1
1
m
Is there some kind of per file or per class annotation to tell the compiler that this file/class is intended to be pure Kotlin as a kind of preparation for a later move to KMP?
l
@uli aren't jvm code and java code the same? Why do I need the java plugin?
u
you can’t use java code for other platforms
l
Do you mean APIs like java.time or something similar?
u
yes. and these APIs won’t be available in KMM but you will only notice after switching
👍 1