JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to create dynamic tasks in Gradle?


You can create dynamic tasks with Gradle using Groovy. The power of Groovy can be used for more than defining what a task does. You cannot create dynamic task in ant or maven.

4.times { counter ->
        task "task$counter" << {
                println "I am task number $counter"
        }
}

Run command gradle tasks to see the task dynamically created:

java2novice$ gradle tasks
:tasks

Other tasks
-----------
task0
task1
task2
task3

To see all tasks and more detail, run with --all.

BUILD SUCCESSFUL

Total time: 2.985 secs

Gradle created 4 dynamic tasks here, the task names also dynamic. Run command gradle task2 to see the output:

java2novice$ gradle task2
:task2
I am task number 2

BUILD SUCCESSFUL

Total time: 1.711 secs

Reference: Gradle Documentation

<< Previous Program | Next Program >>

Gradle configuration examples

  1. Gradle Installation Steps
  2. What is gradle project and task
  3. What is build.gradle file?
  4. How to avoid gradle log messages?
  5. How to define default tasks in Gradle?
  6. How to list all gradle tasks?
  7. How to list gradle project properties?
  8. How to declare a task that depends on other task?
  9. How to create dynamic tasks in Gradle?
  10. How to exclude a task in gradle?
  11. How to create java project in gradle?
Knowledge Centre
Can interface be final?
No. We can not instantiate interfaces, so in order to make interfaces useful we must create subclasses. The final keyword makes a class unable to be extended.
Famous Quotations
The pessimist complains about the wind; the optimist expects it to change; the realist adjusts the sails.
-- William Arthur Ward

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.