How to change name of jar created using shadowjar

13,961

Solution 1

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.

Solution 2

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

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

Solution 3

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

Solution 4

It seems you want to replace -all by -deploy only, just add classifier option to shadowjar:

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

Related videos on Youtube

Ankur Garg
Author by

Ankur Garg

Work at Adobe Systems

Updated on October 20, 2022

Comments

  • Ankur Garg
    Ankur Garg over 1 year

    I am using shadowJar plugin to build/create my fatJar . Inside my build.gradle I have this

    shadowJar{
    mergeServiceFiles('META-INF/spring.*')
    exclude "META-INF/*.SF"
    exclude "META-INF/*.DSA"
    exclude "META-INF/*.RSA"
    exclude "META-INF/LICENSE"
    }
    

    Using gradle shadowJar creates my fat jar . However the name of the fat jar created is something sample-SNAPSHOT-ns.r100-all.jar . I want to change it to sample-SNAPSHOT-ns.r100-deploy.jar . How do u overwrite jar Name using ShadowJar.

  • mernst
    mernst over 7 years
    The Shadow plugin default is archiveName = "${baseName}-${version}-${classifier}.${extension}"
  • fIwJlxSzApHEZIl
    fIwJlxSzApHEZIl about 6 years
    @mernst that command in my build.gradle file throws error Could not get unknown property 'baseName' for root project