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
What is System.out in Java
In System.out, out is an instance of PrintStream. It is a static member variable in System class. This is called standard output stream, connected to console.
Famous Quotations
I don’t know the key to success, but the key to failure is trying to please everybody.
-- Bill Cosby

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 [email protected].

Most Visited Pages

Other Interesting Sites

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