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. 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的更多相关文章
- 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 ren ...
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- 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: Automatic Clean Tasks
Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...
- Gradle Goodness: Unpacking an Archive
To create an archive with Gradle is easy. We have several tasks like Zip, Tar, Jar, War and Ear to c ...
- 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. ...
- Gradle Goodness: Continue Build Even with Failed Tasks
If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...
- Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/lidroid/xutils/task/TaskHandler;
Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files defi ...
随机推荐
- python中logging日志基本用法,和进程安全问题
低配版 import logging logging.debug('debug message') # 调试模式 logging.info('info message') # 正常运转模式 loggi ...
- NOI 2016 区间 解题报告
题目描述 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含至少一个位置.换句话说,就是使得存在一个 x,使得对于每一 ...
- numpy数组的创建
创建数组 创建ndarray 创建数组最简单的方法就是使用array函数.它接收一切序列型的对象(包括其他数组),然后产生一个新的含有传入数据的Numpy数组. array函数创建数组 import ...
- Word 关闭 Passive Voice
Sheryl prefers passive voice for some of her writing (such as business documents and correspondenc ...
- java中方法调用在内存中的体现
在java中,方法以及局部变量(即在方法中声明的变量)是放在栈内存上的.当你调用一个方法时,该方法会放在调用栈的栈顶.栈顶的方法是目前正在执行的方法,直到执行完毕才会从栈顶释放.我们知道,栈是一种执行 ...
- Selenium对浏览器的支持
1.火狐浏览器 优点:FireFox Dirver对页面的自动化测试支持得比较好,很直观地模拟页面的操作,对JavaScript的支持也非常完善,基本上页面上做的所有操作FireFox Driver都 ...
- 打通版微社区(1):PHP环境部署 for DZX3.2
写在前面:本文参考了http://blog.sina.com.cn/s/blog_513be2630101linz.html非常感谢博主此文对我此次操作帮助很大.PHP的windows部署方案主要分为 ...
- 如何递归执行view的动画
如何递归执行view的动画 效果: 山寨的源头: 图片素材: 源码: // // ViewController.m // RepeatAnimationView // // Created by Yo ...
- 将一种cell当做几种cell使用
将一种cell当做几种cell使用 将一种cell当做几种cell用是有着一些意义的,比如,有时候,不同的cell之间差异很小,如果再派生一个cell出来,就会显得很麻烦,这时候,将这个cell当做几 ...
- python传递参数给shell
#格式化字符 print "hello, %s" % ('mm') #传递参数 n="192.168.200.2" os.popen('ping %s -c 2 ...