zoukankan      html  css  js  c++  java
  • Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

    Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have to add this single line and reference our existing Ant build XML file and all Ant tasks can now be executed as Gradle tasks. We can automatically rename the Ant tasks if we want to avoid task name collisions with Gradle task names. We use a closure argument with the importBuild method and return the new task names. The existing Ant task name is the first argument of the closure.

    Let's first create a simple Ant build.xml file:

    00.<project>
    01. 
    02.<target name="showMessage"
    03.description="Show simple message">
    04. 
    05.<echo message="Running Ant task 'showMessage'"/>
    06. 
    07.</target>
    08. 
    09.<target name="showAnotherMessage"
    10.depends="showMessage"
    11.description="Show another simple message">
    12. 
    13.<echo message="Running Ant task 'showAnotherMessage'"/>
    14. 
    15.</target>
    16. 
    17.</project>

    The build file contains two targets: showMessage and showAnotherMessage with a task dependency. We have the next example Gradle build file to use these Ant tasks and prefix the original Ant task names with ant-:

    00.// Import Ant build and
    01.// prefix all task names with
    02.// 'ant-'.
    03.ant.importBuild('build.xml') { antTaskName ->
    04."ant-${antTaskName}".toString()
    05.}
    06. 
    07.// Set group property for all
    08.// Ant tasks.
    09.tasks.matching { task ->
    10.task.name.startsWith('ant-')
    11.}*.group = 'Ant'

    We can run the tasks task to see if the Ant tasks are imported and renamed:

    $ gradle tasks --all
    ...
    Ant tasks
    ---------
    ant-showAnotherMessage - Show another simple message [ant-showMessage]
    ant-showMessage - Show simple message
    ...
    $

    We can execute the ant-showAnotherMessage task and we get the following output:

    00.$ gradle ant-showAnotherMessage
    01.:ant-showMessage
    02.[ant:echo] Running Ant task 'showMessage'
    03.:ant-showAnotherMessage
    04.[ant:echo] Running Ant task 'showAnotherMessage'
    05. 
    06.BUILD SUCCESSFUL
    07. 
    08.Total time: 3.953 secs
    09.$

    Written with Gradle 2.2.1

  • 相关阅读:
    Objective-C之NSArray(数组)默认排序与自定义排序
    Objective-C学习笔记之for( int )机制
    OC之NSString、NSMutableString学习笔记 常用方法
    换行回车的区别 2018-10-30
    Python头部2行 #!/usr/bin/python 和 #!/usr/bin/env 的区别 以及编码方式的指定 2018-10-23
    旧版Windows 睡眠与休眠 2018-10-18
    手机尺寸像素 PPI 2018-10-17
    VMvare 虚拟机扩容 2018-10-11
    批量判断网址能否访问 2018-10-04
    字符串的 strip()方法 2018-10-04
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4187477.html
Copyright © 2011-2022 走看看