tasks {
withType<ShadowJar>().configureEach {
archiveClassifier.set("standalone")
mergeServiceFiles()
minimize {
exclude { // exclude any modules you need to exclude from minimization here
it.moduleName == "something"
}
}
}
withType<Jar>().configureEach {
from(rootProject.file("LICENSE"))
manifest {
attributes(
"Main-Class" to "it.polpetta.Cli",
"Built-By" to System.getProperty("user.name"),
"Built-Date" to Date(),
"Built-Jdk" to System.getProperty("java.version"),
"Implementation-Title" to "JKK: A git-like cli for Jenkins written in Kotlin",
"Implementation-Version" to project.version.toString(),
"Add-Opens" to "java.base/java.lang"
)
}
}
}
Use the shadow plugin to remove unused classes from the jar via minimization.
For example (Kotlin gradle DSL):
This will make your jar significantly lighter