Creating dependent tasks

In this post of gradle, I will show two different ways to make one task depend upon other.

build.gradle


1  task task1 {
2   doFirst {
3       println 'I am dependee'
4   }
5  }
6  
7  task task2(dependsOn: task1) {
8   doFirst {
9       println 'I am dependent1'
10  }
11 }
12 
13 task task3 {
14  doFirst {
15      println 'I am dependent2'
16  }
17 }
18 
19 task3.dependsOn task1

In the first approach I created a dependencies betweeen task2 and task1, in the definition of task2 itself. Please refer to line 7

In the second approach I created a dependencies between task3 and task1. In this approach first I define task3 refer to line 13 to 17. Then I created dependencies by calling dependsOn method available in the task instance.

Leave a Reply