Skip to content

Instantly share code, notes, and snippets.

@apolaskey
Created January 5, 2020 03:56
Show Gist options
  • Save apolaskey/21411c7c7982b1981818cb6b3e766431 to your computer and use it in GitHub Desktop.
Save apolaskey/21411c7c7982b1981818cb6b3e766431 to your computer and use it in GitHub Desktop.
Gradle Kotlin Fat Jar with Main
// Put main in companion object of said class
/*
class App {
companion object {
@JvmStatic
fun main(args: Array<String>) {
System.out.println("Hello")
}
}
}
*/
val jar by tasks.getting(Jar::class) {
manifest {
attributes["Implementation-Title"] = "MyApp"
attributes["Implementation-Version"] = "1.0.0"
attributes["Main-Class"] = "com.server.App"
}
from(configurations.compileClasspath.get().map {
logger.info("File: " + it.name)
if (it.isDirectory) it else zipTree(it)
})
}
// Run with "gradle clean jar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment