https://kotlinlang.org logo
Title
t

Tasos Stamadianos

12/04/2018, 4:18 PM
where can I ask questions about binary compatibility and JVM/JDK versions?
g

gildor

12/04/2018, 4:26 PM
Binary compatibility of Kotlin? This channel is fine for that
t

Tasos Stamadianos

12/04/2018, 4:31 PM
awesome. I think i should have been more specific with my question. Say I'm using a library which is built against Kotlin 1.2.x, but I'm on Kotlin 1.3.x. When I include this lib as a dependency, I get a warning advising me against keeping different versions of runtime JAR files in my classpath. I'm aware that this is likely due to the library in question including Kotlin stdlib as a dependency. Is there a way to fix this? And in a broader scope, if a lib is built against a previous version but does not include the stdlib from that version, will it work with newer Kotlin versions?
as far as I can see, as long as you include the new libs you should be fine
t

Tasos Stamadianos

12/04/2018, 4:41 PM
oh i've never seen this page, thanks
i

ilya.gorbunov

12/04/2018, 7:29 PM
@Tasos Stamadianos Which build system do you use? Gradle, Maven? In general there should be only one version of the standard library in the classpath and it should be consistent with the other kotlin runtime libraries such as
kotlin-reflect
. Could you show the entire warning telling what artifacts have conflicting versions?
t

Tasos Stamadianos

12/04/2018, 9:57 PM
Hi @ilya.gorbunov, thanks for chiming in 🙂 my error is as follows:
Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /home/tasos/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.71/5470d1f752cd342edb77e1062bac07e838d2cea4/kotlin-stdlib-jdk8-1.2.71.jar (version 1.2)
    /home/tasos/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.71/4ce93f539e2133f172f1167291a911f83400a5d0/kotlin-stdlib-jdk7-1.2.71.jar (version 1.2)
    /home/tasos/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.10/b178c1501609c6e4ee8be635513cb023a466457d/kotlin-stdlib-1.3.10.jar (version 1.3)
    /home/tasos/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.10/1b19d99229dcedad7caf50534dce38fe82845269/kotlin-stdlib-common-1.3.10.jar (version 1.3)
I narrowed down the dependency causing this issue to the popular Javalin HTTP framework, which has an issue referencing Kotlin 1.3 support here: https://github.com/tipsy/javalin/issues/434 thanks!!
it looks like this is likely to happen whenever I use a dependency built against an older version of Kotlin
i

ilya.gorbunov

12/04/2018, 11:13 PM
It looks like you depend on
kotlin-stdlib:1.3.10
and Javalin depens on
kotlin-stdlib-jdk8:1.2.71
which itselfs depends transitively on
kotlin-stdlib:1.2.71
. Gradle resolves that transitive dependency version conflict by choosing the highest version of
kotlin-stdlib
, but it's ok from gradle's standpoint to leave
1.2.71
version of stdlib-jdk8. You can resolve this warning by depending explicitly on
kotlin-stdlib-jdk8:1.3.10
.
t

Tasos Stamadianos

12/04/2018, 11:15 PM
ah okay, so changing:
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
to:
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.10")
will fix it?
this is in my
build.gradle.kts
right now it does not specify a version
i

ilya.gorbunov

12/04/2018, 11:17 PM
If you omit version, it should be inferred from the kotlin plugin version.
t

Tasos Stamadianos

12/04/2018, 11:17 PM
okay, i included the version but the warning remains
i

ilya.gorbunov

12/04/2018, 11:17 PM
That's interesting, could you share
build.gradle
or at least
dependencies
section?
t

Tasos Stamadianos

12/04/2018, 11:18 PM
wait, it might be due to inclusion of another lib that's depending on an old version of reflection
one moment
okay, i fixed it by explicitly specifying the reflect lib version
thanks for your help 🙂
out of curiosity, how is binary compatibility handled in this case?
i

ilya.gorbunov

12/04/2018, 11:42 PM
You can substitute older versions with newer ones. However it's important to keep versions of
kotlin
core libraries consistent. To make it easier we're going to provide a bill-of-materials (BOM) artifact in 1.3.20, which lists all these libraries versions to keep them in sync (see https://youtrack.jetbrains.com/issue/KT-18398). This BOM artifact can be used in Maven to pin versions of your dependencies, and AFAIK in Gradle since 5.0.
👍 1