java.lang.ClassNotFoundException: kotlinx.serialization.ElementValueEncoder
See original GitHub issueDescribe the bug
I am building a plugin for minecraft spigot and wanted to store / load settings using Kotlin’s serializable and charleskorn’s Yaml. However, when calling com.charleskorn.kaml.Yaml.stringify
with a serializable data class’ serializer().list from import kotlinx.serialization.builtins.list
I am getting the following error:
Caused by: java.lang.ClassNotFoundException: kotlinx.serialization.ElementValueEncoder
https://pastebin.com/C9hZB7yB
Code that is causing the issue
Yaml.default.stringify(Gauntlet.serializer().list, gauntlets)
Where Gauntlet is a @Serializable
This is my Gradle build file
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
group 'com.krulvis.gauntlet'
version '1.0'
repositories {
mavenLocal()
mavenCentral()
maven {
name = "spigot"
url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
}
}
dependencies {
implementation "com.charleskorn.kaml:kaml:0.15.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.20.0"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.20.0"
compileOnly("org.spigotmc:spigot-api:${minecraft_version}-R0.1-SNAPSHOT")
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
I read somewhere on another issue that some class couldn’t be found and the dependency should be loaded as api rather than compile in dependencies in the gradle build file. I tried both, which didn’t resolve the issue.
Expected behavior Stringify list of serializable data classes Environment
- Kotlin version: 1.3.72
- Library version: 0.20.0
- Kotlin platforms: JVM
- Gradle version: 6
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Thanks for clearing that up! Really appreciate the effort you guys put into this!
Because your dependency (
implementation "com.charleskorn.kaml:kaml:0.15.0"
or maybespigot-api
) is compiled against older version ofkotlinx.serialization
where this class actually exists.You have your application that depends on
0.20.0
version andkaml
that depends on0.15.0
version. These versions are incompatible, so eitherkaml
should be updated, or your own dependency onserialization
downgraded back to0.15.0