Proper way to handle multiple libraries with bundled Kotlin runtime in Gradle


#1

I have a Kotlin application that has dependencies on several libraries written in Kotlin. As far as I can tell the compiler seems to be running into conflict issues with the different runtimes. It also explicitly warns that this may cause problems. I’m wondering what the best way to resolve this issue is in Gradle. Should I not be bundling the Kotlin runtime with my libraries? If I don’t won’t the break in pure Java applications? Should I tell Gradle to ignore the bundled Kotlin runtimes in the other libraries? I’m trying to understand what the best practice for dealing with this issue. If it helps, this issue only started showing up when I converted my application to Kotlin 1.1, the libraries I’m using are on 1.0.X. Here is my compiler output:

Testing started at 2:29 PM ...
2:29:21 PM: Executing external task 'test'...
:compileKotlin
Using kotlin incremental compilation
w: The '-d' option with a directory destination is ignored because '-module' is specified
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath or use '-Xskip-runtime-version-check' to suppress this warning
w: /home/zjuhasz/.gradle/caches/modules-2/files-2.1/com.tenkiv.coral.jdk/core/0.11.0.1-SNAPSHOT/93e632e3693132ec7ed6d0310b1d9bcfb08cc2da/core-0.11.0.1-SNAPSHOT.jar: Library has Kotlin runtime bundled into it
w: /home/zjuhasz/.gradle/caches/modules-2/files-2.1/com.tenkiv.coral/coral/0.7.0.3-SNAPSHOT/78443173a1545e6b05b5308bad38bac8eda54d92/coral-0.7.0.3-SNAPSHOT.jar: Library has Kotlin runtime bundled into it
w: /home/zjuhasz/.gradle/caches/modules-2/files-2.1/com.tenkiv.tekdaqc/java-library/2.1.3.27-SNAPSHOT/b8e65cfed3fffc8cda395e35935799373c5f8e44/java-library-2.1.3.27-SNAPSHOT.jar: Library has Kotlin runtime bundled into it
e: /run/media/zjuhasz/Storage/git/Nexus-Brain/src/main/kotlin/org/tenkiv/nexus/configuration/yaml.kt: (160, 48): Overload resolution ambiguity: 
@InlineOnly public inline fun String.toInt(): Int defined in kotlin.text
@InlineOnly public inline fun String.toInt(): Int defined in kotlin.text
e: /run/media/zjuhasz/Storage/git/Nexus-Brain/src/main/kotlin/org/tenkiv/nexus/data/relationship_table.kt: (63, 31): Overload resolution ambiguity: 
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
e: /run/media/zjuhasz/Storage/git/Nexus-Brain/src/main/kotlin/org/tenkiv/nexus/data/relationship_table.kt: (64, 32): Overload resolution ambiguity: 
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 10.081 secs
Compilation error. See log for more details

#2

I don’t bundle Kotlin runtime in final jar library distribution, it is a simple dependency, write it as first dependency.


#3

I relocate the runtime and stdlib to another package each time using a gradle plugin: https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow

Example: https://github.com/randombyte-developer/holograms/blob/master/build.gradle#L49