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
Can you list serialization methods?
Serialization interface does not have any methods. It is a marker interface. It just tells the JVM that your class can be serializable.
Famous Quotations
You can never get enough of what you don’t really need.
-- Eric Hoffer

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.