如何在gradle zip任务中排除路径信息

时间:2017-12-06 19:31:28

标签: gradle zip build.gradle

为这个简单的问题提前道歉我对Gradle来说相对较新。

我想在构建过程中运行Zip任务,并在我的“archive”目录中创建一个.zip文件,但没有源文件的目录结构。我设法使task正常工作,但保留了目录结构。我读到对于linux Zip,有一个选项-j或-r,它会使目录变平,但我不确定这是否可以通过Gradle任务使用。

My input file structures looks similar to the below,
    ./libs/
    ./libs/file1.jar
    ./scripts/script1.sh
    ./scripts/script2.sh

但我希望最终得到一个包含目录结构的Zip文件,如下所示,

./
./file1.jar
./script1.sh
./script2.sh

我当前的Zip任务如下,

task makeZipForDeploy(type: Zip) {
            from 'build/'
            include 'libs/*' //to include all files in libs folder
            include 'scripts/*' //to include all files in the scripts folder
            archiveName("${archiveFileName}")
            destinationDir file("${archivePath}")
}

1 个答案:

答案 0 :(得分:1)

解决方案比我想象的更微不足道。以下将使结构变平

task makeZipForDeploy(type: Zip) {
    from 'build/libs' //to include all files in libs folder
    from 'build/scripts' //to include all files in the scripts folder
    archiveName("${archiveFileName}")
    destinationDir file("${archivePath}")
}