Gradle Kotlin DSL manifest attribute
What's inside this article
⌄
- Gradle Kotlin no main manifest
- Gradle manifest attribute missing
- Gradle Kotlin main class manifest
- Gradle Kotlin JAR manifest error
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
build.gradle.kts:
tasks.jar {
manifest {
attributes("Main-Class" to "tech.mchesnavskii.MainKt")
}
}
You need to replace the line tech.mchesnavskii.MainKt with your class name. Since tech.mchesnavskii is the name of the package, it may be ommited: they’re not required in Kotlin.
Fat jar (Uber jar) with dependencies
The code template below is taken from my last article.
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.mchesnavskii.MainKt")
}
}