Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change name of jar created using shadowjar

Tags:

gradle

jar

build

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.

like image 719
Ankur Garg Avatar asked Nov 04 '15 16:11

Ankur Garg


3 Answers

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.

like image 140
Stanislav Avatar answered Oct 19 '22 09:10

Stanislav


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

tasks.withType<ShadowJar> {
   archiveFileName.set("${archiveBaseName}-${archiveVersion}-${archiveClassifier}.${archiveExtension}")
}
like image 28
Richard Avatar answered Oct 19 '22 09:10

Richard


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

like image 2
saulpalv Avatar answered Oct 19 '22 10:10

saulpalv