JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to declare a task that depends on other task?


You can declare tasks that depend on other tasks. All you need to do is, use dependsOn keyword to declare dependent tasks. The dependent tasks will be executed first before executing requested task. Look at below example, how we have declared build task dependency with test task:

task test << {
        println 'i am a test task'
}
task build(dependsOn: test) << {
        println "i am build depends on test"
}

Run command gradle build on command-line:

java2novice$ gradle build
:test
i am a test task
:build
i am build depends on test

BUILD SUCCESSFUL

Total time: 1.701 secs

How to declare if your task depends on multiple tasks? It's simple, you can declare multiple tasks seperated by comma, and enclosed with in '[]', here is an example how to declare multiple dependencies:

task clean << {
        println 'i am a clean task'
}
task test << {
        println 'i am a test task'
}
task build(dependsOn: [clean, test]) << {
        println "i am build depends on test"
}

Run command gradle build on command-line:

java2novice$ gradle build
:clean
i am a clean task
:test
i am a test task
:build
i am build depends on test

BUILD SUCCESSFUL

Total time: 2.657 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
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.

wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Famous Quotations
If you don’t make mistakes, you’re not working on hard enough problems. And that’s a big mistake.
-- Frank Wilczek

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.