Issue with dependencies in Kotlin Multiplatform JAR file

Hello everyone,

I’ve developed a Kotlin Multiplatform library that uses kotlinx.serialization for data serialization. However, when I import this library into a Java project and try to use one of its services, I encounter a java.lang.NoClassDefFoundError: kotlinx/serialization/SerializationException error.

I’ve included kotlinx.serialization in the dependencies of my Kotlin Multiplatform library, but it seems these dependencies aren’t properly integrated into the generated JAR.

I should mention that I’m not very experienced with Java development.

Could someone please assist me in understanding how to integrate dependencies like kotlinx into the generated JAR of my Kotlin Multiplatform library so that I can use them correctly in a Java project?

import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
    alias(libs.plugins.multiplatform)
    alias(libs.plugins.kotlinx.serialization)
    id("convention.publication")
    id("org.jetbrains.dokka") version "1.9.20"
    id("org.openapi.generator") version "7.5.0"
}

group = "fr.group.libs"
version = "0.2.0"
val productName = "MyLib"

tasks.dokkaHtml {
    outputDirectory.set(layout.projectDirectory.dir("../documentation/html/$version"))
}

tasks.dokkaGfm {
    outputDirectory.set(layout.projectDirectory.dir("../documentation/Gfm/$version"))
}

kotlin {
    jvm {
        withJava()
    }

    js(IR) {
        browser {
            webpackTask {
                mainOutputFileName.set("$productName-$version.js")
                output.library = productName
                output.libraryTarget = "var"
            }
        }
        generateTypeScriptDefinitions()
        // useEsModules()
        binaries.executable()
    }

    val xcf = XCFramework()
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = productName
            embedBitcode("disable")
            xcf.add(this)
        }
    }

    sourceSets {
        commonMain.dependencies {
            implementation(libs.kotlinx.serialization.json)
            implementation(libs.kermit)
        }

        commonTest.dependencies {
            implementation(kotlin("test"))
        }

    }

    //https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers
    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
        compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc")
    }

}