Question

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?

Was it helpful?

Solution 2

I got it to work by configuring doLast to rename the built archive.

distZip {
    doLast {
        file("$destinationDir/$archiveName").renameTo("$destinationDir/$baseName-$version-bin.zip")
    }
}

OTHER TIPS

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", '')
            }
        }
    }
}
apply plugin: 'application'

While using the application plugin, this is how changed the file name:

distributions {
    main {
        baseName = "watch"
        version = ""
        contents {
            from('.') {
                include '*.yml'
                into "bin"
            }
        }
    }
}

This generated files watch.tar & watch.zip.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top