Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to specify jar name and version both in build.gradle

Tags:

java

gradle

I want to specify the jar name and version in build.gradle, so my build.gradle looks like below.

apply plugin: 'java'  version = "1.00.00"   dependencies {       compile files('../../lib/abc.jar')  }   jar{     manifest{         attributes ("Fw-Version" : "2.50.00", "${parent.manifestSectionName}")      }     archiveName 'abc.jar' } 

So when I do

gradle clean build, what I was expecting was that the generated jar name would be abc-1.00.00.jar

But its not happening, the output jar name is getting as abc.jar only and its just ignoring the version. I want to specify both jar name and version, so how can I achieve that?

like image 450
amuser Avatar asked Jul 14 '15 11:07

amuser


People also ask

How do I mention gradle version in build gradle?

First install Gradle on your machine, then open up your project directory via the command line. Run gradle wrapper and you are done! You can add the --gradle-version X.Y argument to specify which version of Gradle to use.


2 Answers

archiveName 'abc.jar' in your jar configuration is forcing the name to be 'abc.jar'. The default format for the jar name is ${baseName}-${appendix}-${version}-${classifier}.${extension}, where baseName is the name of your project and version is the version of the project. If you remove the archiveName line in your configuration you'll have the format you're after. If you want the name of the archive to be different from the project name set the baseName instead, e.g.

jar {     manifest{         attributes ("Fw-Version" : "2.50.00", "${parent.manifestSectionName}")     }     baseName 'abc' } 

See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveName for more info on configuring the jar task.

like image 88
andyberry88 Avatar answered Oct 10 '22 13:10

andyberry88


For Gradle 5+

build.gradle groovy DSL

archiveBaseName = 'foo' 

build.gradle.kts kotlin DSL

archivesBaseName.set("foo") // Notice the double quotes 
like image 30
Ahmed Kamal Avatar answered Oct 10 '22 11:10

Ahmed Kamal