使用 Gradle 将目录压缩到多个目的地

Zip directory to multiple destinations using Gradle

Gradle 的 Zip 任务是否可以将生成的 zip 复制到多个目的地?

据我所知,您只能使用一个输出目标压缩多个输入目录。有没有办法压缩目录并将存档复制到多个目的地(在一个任务中)?由于我必须使用 Gradle v5.0,因此非常感谢该版本 Gradle 的解决方案。

我建议你在 Zip 任务上使用 Copy task for the copying, and possibly add a 'finalizedBy' statement

复制到多个目标已涵盖here

Zip 任务的内部操作只会将 zip 文件输出到单个目录。如果您不想创建额外的 Copy 任务,您可以使用 doLast 闭包并使用 Project 实例提供的方法 copy

task myZip(type: Zip) {
    ...
    doLast {
        copy {
            from archivePath
            into 'path/to/other/destination'
        }
    } 
}