Gradle Goodness: Renaming Files while Copying
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的更多相关文章
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
- 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 ...
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- 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. ...
- 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 ...
- 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 ...
- 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 ...
- Gradle Goodness: Automatic Clean Tasks
Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...
- 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 ...
随机推荐
- jvm 内存机制
jvm 的内存包括stack ,Heap,NonHeap,在此重点说明Heap,NonHeap. Heap叫堆内存,它用于存放类实例和数组信息.NonHeap叫非堆内存,用于存放类,方法等可反射的对象 ...
- For循环中由于ajax异步导致的问题解决(增加alert数据正常,去掉alert之后数据错误)
由于ajax异步请求的机制,for循环运行不会等内部ajax请求结束,而直接循环到最后.解决方法:将for循环里面的请求单独封装一个方法. 个人遇到的问题具体如下 下面这段代码,如果第5行studat ...
- Java:反射与代理
Java世界的繁荣反射这一特性有很大功劳,可以获取全面的类型信息. /** * */ package ref; import java.lang.reflect.Field; import java. ...
- canvas toDataURL() 方法如何生成部分画布内容的图片
HTMLCanvasElement.toDataURL() 方法返回一个包含图片展示的 data URI .可以使用 type参数其类型,默认为 PNG 格式.图片的分辨率为96dpi. 如果画布的高 ...
- Ubuntu 17.04 upgrade to 17.10
Just try sudo do-release-upgrade if you get this An upgrade from 'zesty' to 'bionic' is not support ...
- Android开发如何定制framework层服务
刚刚跨完年,新年第一篇文章,那么今天将对Android开发framework中间层的服务定制使用作个总结.首先我们先导入Android平台源码framework层的代码到开发工具eclipse中,代码 ...
- Springmvc和Mybatis中常用的注解
使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package ...
- Eclipse 中出现红色下划波浪线与红色感叹号
一直用eclipse写Python,老是看到一些字符串都给出红色波浪线, 看着就不舒服.弄了老半天终于消除了,原来是拼写检查 Windows->Preferences->General-& ...
- net 4.0+EF6+Sqlite 使用,安装,打包
开发 1.因为EF不支持Codefirst,开始可以使用SQL来进行开发. 部署安装 2.然后可以找到SQL转Sqlite工具(http://www.cnblogs.com/walkingp/arch ...
- time random sys 模块
time模块 顾名思义就是时间模块 我们在之前就用过一些时间模块 比如你想要让打印的时间延迟就time.sleep() 首先我们知道这是一个时间操作的模块 它可以分为三种模式:时间戳模式.格式化时间模 ...