gradle distZip rename archive

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.


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", '')
            }
        }
    }
}

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

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