码迷,mamicode.com
首页 > 其他好文 > 详细

Gradle Goodness: Renaming Files while Copying

时间:2014-12-27 20:17:35      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/GoAhead/p/4189089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!