Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle distZip rename archive

I want to use a specific name to the distributable zip archive created by distZip task. I used below code

distZip {
        archiveName baseName+'-'+version+'-bin.zip'
}

Generated archive contains 'baseName+'-'+version+'-bin' folder in it.


    jar -tvf baseName-version-bin.zip 
        0 Mon Feb 24 15:48:02 CST 2014   baseName-version-bin/
     81462 Mon Feb 24 15:48:02 CST 2014  baseName-version-bin/baseName-version.jar
         0 Mon Feb 24 15:48:02 CST 2014  baseName-version-bin/lib/
    6329376 Fri Feb 07 09:37:28 CST 2014 baseName-version-bin/lib/a.jar
    6329376 Fri Feb 07 09:37:28 CST 2014 baseName-version-bin/lib/b.jar

All the jars were placed inside this directory. I just want to rename the archive and not disturb the contents in it. I was expecting 'baseName-version' directory without '-bin' suffix inside the zip.

How do I alter the name of archive alone?

like image 520
suman j Avatar asked Feb 24 '14 21:02

suman j


1 Answers

You can do it as follows:

distZip {
    archiveName "$baseName-$version-bin.zip"
}

distributions {
    main {
        contents {
            eachFile {
                it.path = it.path.replace('-bin', '')
            }
        }
    }
}

Another thing is, for adding such suffix like -bin better way (and compatible with maven) would be using classifier property. I'm using java-library-distribution plugin but I believe with distribution plugin it should work the same (considering you are using maven plugin as well). Then it is enough you do it like:

distZip {
    classifier = 'bin'
}

distributions {
    main {
        baseName = archivesBaseName
        contents {
            eachFile {
                it.path = it.path.replace("-$distZip.classifier", '')
            }
        }
    }
}
like image 180
topr Avatar answered Sep 19 '22 12:09

topr