https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Alex Styl

03/27/2024, 10:53 AM
im having troubles creating a jar from my desktop app. I am using
ShadowJar
for it but the jar created throws an exception when run. I use this configuration :
Copy code
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    // ...
    id("com.github.johnrengelman.shadow") version "8.1.1"
    id("java")
}

tasks.withType<ShadowJar> {
    manifest {
        attributes.put("Main-Class", "MainKt")
    }

    val target = kotlin.targets.named("desktop").get()
    from(target.compilations["main"].output)
    val runtimeClasspath = target.compilations["main"].compileDependencyFiles
    configurations = mutableListOf(runtimeClasspath)
}
I then run the jar with
Copy code
java -jar ./composeApp/build/libs/composeApp-all.jar
and it gives me:
Copy code
Exception in thread "main" java.lang.NoClassDefFoundError: androidx/collection/ScatterMapKt
        at androidx.compose.runtime.collection.ScopeMap.<init>(ScopeMap.kt:26)
        at androidx.compose.runtime.CompositionImpl.<init>(Composition.kt:479)
        at androidx.compose.runtime.CompositionImpl.<init>(Composition.kt:434)
        at androidx.compose.runtime.CompositionKt.Composition(Composition.kt:335)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:217)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
was anyone able to do this?
Figured it out. Had to add some compose stuff
Copy code
tasks.withType<ShadowJar> {
    manifest {
        attributes.put("Main-Class", "MainKt")
    }

    val target = kotlin.targets.named("desktop").get()
    from(target.compilations["main"].output)

    val runtimeClasspath = target.compilations["main"].compileDependencyFiles
    configurations = mutableListOf(
        runtimeClasspath,
        project.configurations["desktopCompileClasspath"],
        project.configurations["desktopRuntimeClasspath"],
    )
}
21 Views