Search code examples
gradlejarbuild

How to change name of jar created using shadowjar


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.


Solution

  • 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.