zoukankan      html  css  js  c++  java
  • 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:

  • 相关阅读:
    Git 最全命令使用
    git 配置(实用)
    用Redis进行实时数据排名
    最长上升子序列
    KMP算法
    计算星期几【基姆拉尔森公式】
    集合划分(贝尔数)
    合数分解(质因数分解)
    乘法逆元
    扩展欧几里得算法
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4189108.html
Copyright © 2011-2022 走看看