I tried 3 different ways, inlcuding Idea - Project Structure - Artifacts
and fatJar
, so the error is:
Error: Could not find or load main class MainKt
While my main
has no package (root dir) and it’s a plain Main.kt
:
fun main(args: Array<String>) = runBlocking {
Gradle Kotlin:
tasks {
val fatJar = register<Jar>("fatJar") {
dependsOn.addAll(listOf("compileJava", "compileKotlin", "processResources")) // We need this for Gradle optimization to work
archiveClassifier.set("standalone") // Naming the jar
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// manifest.attributes["Main-Class"] = "MainKt"
manifest { attributes(mapOf("Main-Class" to application.mainClass)) } // Provided we set it up in the application plugin configuration
val sourcesMain = sourceSets.main.get()
val contents = configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) } +
sourcesMain.output
from(contents)
}
build {
dependsOn(fatJar) // Trigger fat jar creation during build
}
}
Looks like it’s another issue. Last problem was to include the necessary libs.