How to change name of jar created using shadowjar

The ShadowJar plugin provides a Jar task extension. Configure it using the archiveFileName property, such as:

shadowJar{
    mergeServiceFiles('META-INF/spring.*')
    exclude "META-INF/*.SF"
    exclude "META-INF/*.DSA"
    exclude "META-INF/*.RSA"
    exclude "META-INF/LICENSE"
    archiveFileName = "sample-${classifier}-ns.r100-deploy.${extension}"
}

You can use placeholders like ${baseName}, ${appendix}, ${version}, ${classifier} and ${extension}.

Note that archiveName is now archiveFileName, as of ShadowJar version 4.


For people looking how to do this with the Kotlin DSL it this:

tasks.withType<ShadowJar> {
   archiveFileName.set("${archiveBaseName}-${archiveVersion}-${archiveClassifier}.${archiveExtension}")
}

combining the answers of @richard and @christian-dräger

tasks.withType<ShadowJar> {
    archiveFileName.set("${project.name}-${project.version}.jar")
}

this outputs the format myProject-0.0.1.jar

Tags:

Build

Jar

Gradle