Gradle goodness:rename ant Task Names when importing ant Build File

Source: Internet
Author: User

Migrating from Ant to Gradle are very easy and the importBuild method from AntBuilder . We are only having to add the reference existing ant build XML file and all ant tasks can now is executed a s 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:

View Sourceprint? 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 the targets: And with showMessage showAnotherMessage 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- :

View Sourceprint? 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 is 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:

View Sourceprint? 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

Gradle goodness:rename ant Task Names when importing ant Build File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.