Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How to partition a task into sequentially executed actions

Is it possible to nest tasks in gradle, such as

task foo(dependsOn: jar){
    // task 1
    // task 2
    // task 3
    .
    .
    .
    // task n
}

where the order of execution is jar > foo > task 1 > task 2 > task 3 > ... > task n? I don't want the nested tasks (i.e. task 1, task 2, and etc.) to be exposed to the user. I only want the foo task to be exposed.

like image 745
user1329572 Avatar asked Sep 12 '12 16:09

user1329572


1 Answers

It looks like you can simply do the following,

task foo(dependsOn: ['clean', 'jar']){
    foo << {
        println "First"
    }
    foo << {
        println "Second"
    }

    foo << {
        println "Third" 
    }
    .
    .
    .
}

where << is shorthand for doLast. I think the neat thing about this approach is that only foo is exposed..the nested tasks remain hidden from the end user. And if you execute foo, you'll get

First
Second
Third
like image 135
user1329572 Avatar answered Nov 14 '22 23:11

user1329572