Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get gradle to ignore version number in jar name

Tags:

gradle

I have a project that has to build about 10 different dummy jars for unit testing. I have a gradle project setup like this

project(':CodeTools_dummydriver-true') {
    ext.dummyDriver = true
    archivesBaseName = "dummydriver-true"
}

But the problem is the jarfile is still named dummydriver-true-0.0.1.jar. Is there any way I can tell gradle to ignore the standard pattern and please name the output file what I want it to be named? Meaning, without the version number?

like image 723
scphantm Avatar asked Oct 24 '14 01:10

scphantm


2 Answers

The Java plugin defines the jar task to follow the following template for archiveName:

${baseName}-${appendix}-${version}-${classifier}.${extension}

I don't think there's a way to apply a new "naming template", but what you can do is to explicitly set your jar task's archive name, like this. (Also, isn't it a good idea to use the dummyDriver property directly, instead of hardcoding "true" into the archive name?)

archivesBaseName = "dummydriver"
jar.archiveName = "${jar.baseName}-${dummyDriver}.${jar.extension}"

Alternately, set the version property to null or an empty string, like suggested in Circadian's answer, but if you ever want to use the version property for anything, you don't want to destroy it.

like image 63
Jolta Avatar answered Sep 20 '22 21:09

Jolta


Adding a version property and setting its value to an empty string worked for me.

Here is an example:

project(':CodeTools_dummydriver-true') {
    ext.dummyDriver = true
    archivesBaseName = "dummydriver-true"
    version= ""
}

Hope that helps.

like image 43
Circadian Avatar answered Sep 20 '22 21:09

Circadian