Kotlin jar building error: Could not find or load main class MainKt

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.

It looks like the problem appears because of firebase:

implementation("com.google.firebase:firebase-admin:9.1.1")

Turning it on on an empty project provides same error

When the error happens: when building or running? You description sounds like this is during building, but I would expect it to happen when running. If running, please check contents of your fatjar. It should build somewhere in build/libs/*-standalone.jar or something similar.

The error happens after executing the app:

/usr/lib64/jvm/java/bin/java -Dfile.encoding=UTF-8 -jar Untitled1-1.0-standalone.jar
Error: Could not find or load main class MainKt
Caused by: java.lang.ClassNotFoundException: MainKt