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. Bootstrap网格

    首先了解一下,什么是网格? 在平面设计中,网格是一种由一系列用于组织内容的相交的直线(垂直的.水平的)组成的结构(通常是二维的).它广泛应用于打印设计中的设计布局和内容结构.在网页设计中,它是一种用于 ...

  2. MathQuill.js

    MathQuill.js通过html.css.javascript实现数学公式 <p>Type math here: <span id="math-field"& ...

  3. python 静态 封装 继承 mro 接口 super

    1.静态属性 静态方法  类方法 #!/usr/bin/python env # encoding: utf-8 # 静态属性 静态方法 class Room: tag = 168 def __ini ...

  4. 转载:什么才是真正的 RESTful 架构

    What? Wikipedia: 表征性状态传输(英文:Representational State Transfer,简称REST)是Roy Fielding博士于2000年在他的博士论文中提出来的 ...

  5. Win10设置多时区时钟方法技巧

    Win10设置多时区时钟方法技巧,本文小编将向大家介绍如何设置多个时区时钟,以及如何使用「闹钟和时钟」应用跟踪更多时区,感兴趣的朋友可以参考下面教程操作. Win10系统允许用户配置最多3个不同的时钟 ...

  6. 使用PowerShell批量注册DLL到GAC

    一段很小的代码,注册当前目录下所有的DLL到GAC,请先把gacutil.exe复制到同一个目录. $Path = Get-Location $Dir = Get-ChildItem "$P ...

  7. + - ! function($) (), function 前面的符号意思

    如果在function之前加上感叹号 (!) 会怎么样?比如下面的代码: !function(){alert('iifksp')}()        // true 在控制台运行后得到的值时true, ...

  8. The good life is one inspired by love and guided by knowledge

    The good life is one inspired by love and guided by knowledge 伯特兰·罗素Bertrand Russell18721970 I can a ...

  9. 如何将本地项目上传至GitHub

    首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下载地址,下载后一路直接安装即可: https://gi ...

  10. Coursera 算法二 week 5 BurrowsWheeler

    本打算周末完成这次作业,但没想到遇到了hard deadline,刚开始看不懂题意,后来发现算法4书上有个类似的问题,才理解了题意.最后晚上加班,上课加班,还好在11:35也就是课程结束前25分钟完成 ...