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
Default value of a local variables?
The local variables are not initialized to any default values. We should not use local variables with out initialization. Even the java compiler throws error.
Famous Quotations
Success consists of going from failure to failure without loss of enthusiasm.
-- Winston Churchill

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to java2novice@gmail.com or you can comment on the page.

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.