Gradle-如何在没有父目录的情况下创建distZip? [英] Gradle - how to create distZip without parent directory?

查看:138
本文介绍了Gradle-如何在没有父目录的情况下创建distZip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle的distZip任务使用以下结构创建一个zip

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
    |-- ...

推荐答案

默认情况下是不可能的,但是可以遍历所有文件,这些文件将包含在最终的zip文件中,并在此zip文件中修改其目标路径,为:

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()))
    }
}

这是添加的其他distZip任务配置,该配置修改了最终zip归档文件中每个文件的目标路径,并从其中删除了根文件夹.就您而言,它将从zip删除MyApp文件夹.

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.

这篇关于Gradle-如何在没有父目录的情况下创建distZip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆