Gradle zip:如何轻松包含和重命名一个文件? [英] Gradle zip: how to include and rename one file easily?

查看:194
本文介绍了Gradle zip:如何轻松包含和重命名一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在目录"foo/bar"下的"hello/universe.xml"

task myZip(type: Zip) {
     from ("foo/bar") {
         include "hello/world.xml"
         filesMatching("hello/*") {
             it.path = "hello/universe.xml"
         }
     }
}

filesMatching(...)将明显影响性能. 有什么更好的方法?像:

filesMatching(...) will impact performance obviously. What is a better way? like:

task myZip(type: Zip) {
     from ("foo/bar") {
         include ("hello/world.xml") {
              rename "hello/universe.xml"
         }         
     }
}

但是include不支持rename.

推荐答案

我根本不明白为什么要使用filesMatching.您在孩子中仅包含一个文件 CopySpec .只需重命名即可,一切都很好:

I don't get why you are using filesMatching at all. You are only including one single file in your child CopySpec. Simply rename it and everything is fine:

task myZip(type: Zip) {
    from ('foo/bar') {
        include 'hello/world.xml'
        rename { 'hello/universe.xml' }
    }
}

如果要包含多个文件(甚至复制所有文件),但只想重命名其中一个,请指定要使用正则表达式作为第一个参数重命名的文件:

If you want to include multiple files (or even copy all), but only want to rename one of them, specify which file(s) to rename with a regular expression as first argument:

task myZip(type: Zip) {
    from 'foo/bar'
    rename 'hello/world.xml' 'hello/universe.xml'
}

这篇关于Gradle zip:如何轻松包含和重命名一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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