Search code examples
kotlinstandard-library

Which standard library to use in Kotlin


In Kotlin, when working with the JVM, it seems there is multiple choices for standard library, namely kotlin-stdlib, kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8.

I cannot, however, find anything telling me the difference between these. The only visible difference I have found is that I cannot use com.fasterxml.jackson.databind.exc.MismatchedInputException with kotlin-stdlib, but I can with kotlin-stdlib-jdk8.

Is there anywhere I can read about the advantages using one over the others, or can anyone explain this in layman terms?


Solution

  • As of Kotlin 1.8, the different standard libraries have been merged, and you can just use kotlin-stdlib. JVM targets 1.6 and 1.7 are not supported anymore.

    Updated JVM compilation target

    In Kotlin 1.8.0, the standard libraries (kotlin-stdlib, kotlin-reflect, and kotlin-script-*) are compiled with JVM target 1.8. Previously, the standard libraries were compiled with JVM target 1.6.

    Kotlin 1.8.0 no longer supports JVM targets 1.6 and 1.7. As a result, you no longer need to declare kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 separately in build scripts because the contents of these artifacts have been merged into kotlin-stdlib.

    note

    If you have explicitly declared kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 as dependencies in your build scripts, then you should replace them with kotlin-stdlib.

    Note that mixing different versions of stdlib artifacts could lead to class duplication or to missing classes. To avoid that, the Kotlin Gradle plugin can help you align stdlib versions.

    What's new in Kotlin 1.8 - Updated JVM compilation target