With the Gradle copy task we can define renaming rules for the files that are copied. We use the rename() method of the copy task to define the naming rules. We can use a closure where the filename is the argument of the closure. The name we return from the closure is the new name of copied file. Or we can define a regular expression and set the replacement value for the corresponding regular expression. We can use groups in the regular expression and use them in the replacement value like $<group>.

0.task copyFiles(type: Copy) {
1.from 'src/files'
2.into "$buildDir/files"
3.rename '(.*)-(.*).html', '$2/$1.html'
4.rename ~/(.*).template.(.*)/, '$1.$2'
5.rename { filename ->
6.filename.replace 'java', 'groovy'
7.}
8.}

Let's create some source files, so the renaming rules can be applied to them.

src/files/index-en.html:

<html>
<body>
<h1>Hello Gradle</h1>
</body>
</html>

src/files/index-nl_NL.html:

<html>
<body>
<h1>Hallo Gradle</h1>
</body>
</html>

src/files/sample.template.txt:

Sample file.

src/files/Sample.java:

public class Sample {
private String gradle = "Gradle";
}

We run $ gradle copyFiles and we get the following files in build/files:

nl_NL
|
+-- index.html
en
|
+-- index.html
Sample.groovy
sample.txt

Gradle Goodness: Renaming Files while Copying的更多相关文章

  1. Gradle Goodness: Copy Files with Filtering

    Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...

  2. Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task

    With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. Thi ...

  3. Gradle Goodness: Task Output Annotations Create Directory Automatically

    Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...

  4. Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

    Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...

  5. Could not resolve all files for configuration;Andriod在build.gradle添加compile files()报错

    在build.gradle中添加个 compile files('libs/alipaySdk-20170922.jar') 就一直报这个错误 Error:Could not resolve all ...

  6. Gradle Goodness: Add Incremental Build Support to Tasks

    Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unle ...

  7. Gradle Goodness: Add Incremental Build Support to Custom Tasks with Annotations

    In a previous post we learned how we can use the inputs and outputs properties to set properties or ...

  8. Gradle Goodness: Automatic Clean Tasks

    Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...

  9. Gradle Goodness: Adding Tasks to a Predefined Group

    In Gradle we can group related tasks using the group property of a task. We provide the name of our ...

随机推荐

  1. PAT 1052. Linked List Sorting

    这场考试当年还参加了,当时直接用内置的排序了,否则自己写归并排序浪费时间啊,现在来练习一发.估计又有些节点没在链表里面,当时没考虑这个情况,所以一直有些case没过 #include <iost ...

  2. 教程:让你的表单升级到CSS3和HTML5客户端验证

    今天我们一起来看看如何创建一个实用并且功能强大的表单,表单使用如今最热门的技术HTML5和css3来创建,并且可以通过HTML5进行客户端验证. 查看预览下载附件 第一步:策划表单功能 首先,我们得为 ...

  3. iView开始结束时间组件

    演示地址:https://run.iviewui.com/TGIKGkIt 测试页面文件: <template> <div> <startEndTime @newEndT ...

  4. 使用js在HTML中自定义字符串格式化方法

    Python中支持字符串格式化,其基本形式如下: str = "I'm {name},{age} years old" print(str.format(name="te ...

  5. javascript的 热点图怎么写

    在gis中,你如果用js来写热点图 不借助后台怎么搞,as的话比较容易有相应的类库甚至官方都有.而且用js不借助arcgis发布rest服务,(注:热点图可以借助服务的形式发布,arcgis for ...

  6. Spring IOC (DI-依赖注入)

    看到一篇文章,讲Spring的依赖注入讲的很好理解,也很容易理解,非常详细.原文地址: https://blog.csdn.net/javazejian/article/details/5456130 ...

  7. 软工读书笔记 week 1

    这次读书笔记主要是就<程序员修炼之道>这本书的前半部分做一些总结以及发表一些自己的看法. 本书前面的一部分主要是一些程序员应该在工作中时刻注意的事情,一些关键的信息如下: 1.处理问题的态 ...

  8. maven(十)-继承

     继承 如果项目划分了多个模块,都需要依赖相似的jar包,只需要创建一个父模块,在它的pom.xml文件中配置依赖jar包.功能模块只需要继承父模块,就可以自动得到其依赖jar包,而不需要在每个模 ...

  9. 有关平台支持的从经典部署模型到 Azure Resource Manager 的迁移的技术深入探讨

    本文将深入探讨如何从 Azure 经典部署模型迁移到 Azure Resource Manager 部署模型. 本文将介绍资源和功能级别的资源,让用户了解 Azure 平台如何在两种部署模型之间迁移资 ...

  10. mysql那些招

    show table status mysql官方文档在 http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html 这里的rows行是 ...