You can get this error if you try to run jar without specifying the name of the class that contains fun main()
and which you want to run.
To do this, you need to register the full class name in the Main-Class
key of your manifest.
Plain jar without dependencies
tasks.jar {
manifest {
attributes("Main-Class" to "tech.mchesnavsky.MainKt")
}
}
You need to replace the line tech.mchesnavsky.MainKt
with your class name. tech.mchesnavsky
is the name of the package, it may not be there.
Fat jar (Uber jar) with dependencies
The code template below is taken from my last article: https://mchesnavsky.tech/uber-jar-with-gradle-kotlin-dsl/
tasks.register<Jar>("uberJar") {
archiveClassifier.set("uber")
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
manifest {
attributes("Main-Class" to "tech.mchesnavsky.MainKt")
}
}
That’s all.
Telegram channel
If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.
If I saved your day, you can support me 🤝