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. 插件式WebApi服务及自动生成Api帮助文档

    上一篇博客中,讲到了将WebApi Host到控制台和IIS,本篇总结一下如何将WebApi的Service以插件的形式进行动态部署,并设置Hoster的首页显示Api帮助文档,当然,也包括动态部署进 ...

  2. JavaWeb学习总结(五):HttpServletRespone对象(一)

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...

  3. js Object 的冻结、密封、扩展的相同以及不同点

    Object.freezed() 冻结 检查函数 Object.isFrozen(obj) Object.seal() 密封   检查函数 Object.isSealed(obj) Object.pr ...

  4. 整理一下最近Android面试的提问

    java相关: 1. public protect private default关键字有什么区别? public:表示可以在任何一个类中被访问: protect:表示可以在自身.子类以及同一包下的类 ...

  5. Integer 和 int 值比较

    int 是基本数据类型,会进池,可以使用 == 判断两个值相等 Integer是对象,比较对象不能使用 == , 可以使用Integer.intValue()将取出对象值比较

  6. Java基础之StringBuffer和StringBuilder的区别

    StringBuffer是一个字符串的缓存类,属于一个容器,对于容器,我们可以进行增删改查. StringBuffer的容器长度是可变的,并且里面可以存放多种的数据类型.它跟其他容器,比如数组,是很不 ...

  7. Spring Boot框架搭建

    用idea搭建Springboot还是很方便的 环境变量是JDK1.8 SpringBoot自带了Tomcat启动也很方便 1.创建项目 2. 3.选择SpringBoot的版本以及组件 4.创建完成 ...

  8. Oracle案例08——xx.xx.xx.xx,表空间 SYSAUX 使用率>95%%

    本实例主要针对Oracle表空间饱满问题处理方法做个步骤分享.  一.告警信息 收到zabbix告警信息,表空间 SYSAUX 使用率>95%%,系统表空间sysaux使用率超过了95%. 二. ...

  9. Python学习---django多对多自定义第三方表180206

    案例一: # version: python3.2.5 # author: 'FTL1012' # time: 2018/2/6 16:25 from django.db import models ...

  10. 【转】15个必须知道的chrome开发者技巧

    一.快速切换文件 如果你使用过sublime text,那么你可能不习惯没有Go to anything这个功能的覆盖.你会很高兴听到chrome开发者功能也有这个功能,当DevTools被打开的时候 ...