Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - how to create distZip without parent directory?

Tags:

gradle

Gradle's distZip task creates a zip with the following structure

MyApp.zip
`-- MyApp
    |-- bin
    |   |-- ...
    `-- lib
        |-- ...

how to skip the parent directory and just zip the files like below

MyApp.zip
|-- bin
|   |-- ...
`-- lib
    |-- ...
like image 870
Krishnaraj Avatar asked Feb 16 '16 08:02

Krishnaraj


1 Answers

It's not possible by default, but it is possible to travrse all the files, which will be included into the final zip and modify it's destination path in this zip, as:

distZip {
    eachFile { file ->
        String path = file.relativePath
        file.setPath(path.substring(path.indexOf("/")+1,path.length()))
    }
}

Here is the additional distZip task's configuration added, which modifies each file's destination path within the final zip-archive, deleting the root folder from it. In your case, it will delete the MyApp folder from the zip.

like image 138
Stanislav Avatar answered Nov 01 '22 21:11

Stanislav