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

Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task

时间:2014-12-27 21:38:19      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

With the copy task of Gradle we can copy files that are parsed by Groovy‘s SimpleTemplateEngine. This means we can expand properties in the source file and add Groovy code that is going to be executed. We must use the expand() method in the copy task where we can pass properties to be used in the source file.

00.version = ‘DEMO‘
01.group = ‘com.mrhaki‘
02. 
03.task copy(type: Copy) {
04.from ‘src/templates‘
05.into "$buildDir"
06.include ‘projectinfo.html.template‘
07.rename { file -> ‘projectinfo.html‘ }
08.expand(project: project, title: ‘ProjectInfo‘, generated: new Date())
09.}

We define the following source file in src/templates/projectinfo.html.template:

00.<html>
01.<head>
02.<title>${title}</title>
03.</head>
04.<body>
05.<h1>${project.name}</h1>
06. 
07.<ul>
08.<% project.properties.findAll { k,v -> v instanceof String }.each { key, value -> %>
09.<li>$key = $value</li>
10.<% } %>
11.</ul>
12. 
13.<hr />
14.<p>Generated on ${generated.format(‘dd-MM-yyyy‘)}</p>
15.</body>
16.</html>

When we run the copy task we get the following output:

技术分享

Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task

标签:

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

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