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

huangapple go评论64阅读模式
英文:

Zip directory to multiple destinations using Gradle

问题

能否使用Gradle的Zip任务将结果zip复制到多个目标位置?

据我所知,您只能使用一个输出目标将多个输入目录压缩成一个zip。有没有一种方法可以将目录压缩并将存档复制到多个目标位置(在一个单独的任务中)?由于我必须使用Gradle v5.0,非常希望能够为该版本的Gradle找到解决方案。

英文:

Is it possible with Gradle's Zip task to copy the resulting zip into multiple destinations?

AFAIK you can only zip multiple input directories with only one output destination. Is there a way to zip a directory and copy the archive to multiple destinations (in one single task)? Since I'm bound to using Gradle v5.0, a solution for that version of Gradle would be highly appreciated.

答案1

得分: 1

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

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

The internal action of Zip tasks will only output the zip file to a single directory. If you don't want create additional Copy tasks, you may use a doLast closure and use the method copy provided by the Project instance.

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

答案2

得分: 0

我建议您使用一个复制任务来进行复制操作,并可能在Zip任务上添加一个‘finalizedBy’语句

有关将内容复制到多个目标的信息可以在这里找到。

英文:

I suggest you use a Copy task for the copying, and possibly add a 'finalizedBy' statement on the Zip task.

Copying into multiple destinations is covered here.

huangapple
  • 本文由 发表于 2020年10月2日 16:09:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64168200.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定