https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Stefán Freyr Stefánsson

01/19/2021, 1:14 PM
Hello gang. Can anyone explain the kotlin artifact structure to me a bit? Specifically I’m interested in the kotlin-stdlib-jdk8 package. I’m creating a Quarkus app and I’m using Java 11 but it seems that I still have to declare a dependency on the -jdk8 package. As there is no -jdk11 package I assume this is all fine and correct… but I kind of want to understand what the idea behind this package is exactly.
d

Dmitry

01/19/2021, 1:32 PM
AFAIK
jdk-8
currently is what you want to use. To answer “why” we want to talk about history a bit. Main “stdlib” can be used for Java 1.6. This is important to keep backward compatibility, especially when we think about folks developing for android back in the days when Kotlin first emerged. But Java moved forward and Java 1.7, and then Java 1.8 released. So, you get
stdlib-jdk7
and
stdlib-jdk8
accordingly. Those contains additional extension functions for API’s that were added in those Java versions.
Java’s that were released after 8 did not had API’s that required additional extensions (I guess), so no new stdlibs were published.
Weirdly, only explanation for this in docs can be found on
Maven
page: https://kotlinlang.org/docs/reference/using-maven.html
If you’re targeting JDK 7 or JDK 8, you can use extended versions of the Kotlin standard library which contain additional extension functions for APIs added in new JDK versions. Instead of
kotlin-stdlib
, use
kotlin-stdlib-jdk7
or
kotlin-stdlib-jdk8
, depending on your JDK version (for Kotlin 1.1.x use
kotlin-stdlib-jre7
and
kotlin-stdlib-jre8
as the
jdk
counterparts were introduced in 1.2.0).
s

Stefán Freyr Stefánsson

01/19/2021, 1:36 PM
Thanks! That answers my questions 🙂
v

Vampire

01/19/2021, 2:27 PM
Actually you shouldn't declare the stdlib at all anymore, the Gradle plugin will do it for you, including the language variant matching your environment iirc 🙂
😯 1
💯 1
d

Dmitry

01/19/2021, 2:35 PM
https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library Yeap, this is how it works. Thanks @Vampire, will remove my stdlib’s 😅
👌 1
s

Stefán Freyr Stefánsson

01/22/2021, 9:45 AM
hmmm…
Copy code
Cannot access built-in declaration 'kotlin.String'. Ensure that you have a dependency on the Kotlin standard library
Doesn’t seem to work for me. Is this maybe new in 1.4 @Vampire? I have a Quarkus project that seems to still be dependant on 1.3.
v

Vampire

01/22/2021, 10:16 AM
Yes, that's new in the 1.4 Gradle plugin, sorry to not have mentioned 🙂
s

Stefán Freyr Stefánsson

01/22/2021, 10:17 AM
no worries 🙂 good to know
2 Views