I have a kotlin multi-platform project with sub mo...
# announcements
v
I have a kotlin multi-platform project with sub module
build.gradle.kts
below, but it is not creating a runable jar
Copy code
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    kotlin("multiplatform")
    java
    application
    id("com.github.johnrengelman.shadow") version ("5.2.0")
}

group = "com.kotlin.mpf.server"
version = "1.0-SNAPSHOT"


val ktorVersion = "1.4.0"

repositories {
    //repos
}

kotlin {
    sourceSets {
        jvm().compilations["main"].defaultSourceSet {
            dependencies {
                //--dependencies
            }
        }
    }
}


application {
    mainClassName = "com.vhl.inventory.server.MainKt"
}

tasks.withType<ShadowJar> {
    baseName = "kotlin-mpf-runnable"
    classifier = null
    version = null
}
when ever i try to run the created fat jar, follows an error below
Copy code
java -jar fat.jar

Error: Could not find or load main class com.vhl.inventory.server.MainKt
Caused by: java.lang.ClassNotFoundException: com.vhl.inventory.server.MainKt
has anyone done runnable jar in multi-platform project
n
i remember i had to search in the shadowjar issues for a workaround.. it does not copy the jvm class files from multiplatform projects properly into the fat jar by default
Copy code
// required workarounds because shadowjar does not work with mpp by default
    val shadowJar by existing(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
        group = "shadow"
        dependsOn(populateWebFolder)
        manifest {
            attributes["Main-Class"] = project.application.mainClassName
        }
        archiveClassifier.set("all")
        from(kotlin.jvm().compilations.getByName("main").output)
        configurations = mutableListOf(
            kotlin.jvm().compilations.getByName("main").compileDependencyFiles as Configuration,
            kotlin.jvm().compilations.getByName("main").runtimeDependencyFiles as Configuration
        )
    }
250 Views