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 >>
blog comments powered by Disqus

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
What is fail-fast in java?
A fail-fast system is nothing but immediately report any failure that is likely to lead to failure. When a problem occurs, a fail-fast system fails immediately. In Java, we can find this behavior with iterators. Incase, you have called iterator on a collection object, and another thread tries to modify the collection object, then concurrent modification exception will be thrown. This is called fail-fast.
Famous Quotations
Be yourself; everyone else is already taken.
-- Oscar Wilde

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.