简体   繁体   中英

How to create a Gradle Task

I want to create a gradle task to perform below things -

  • Launches the Google Cloud Engine local development server
  • Runs all tests Shuts the
  • Server down again

There are seperate tasks already defined but i want to know how to combine all of three of them into one.

You could define a new task that calls all of those existing tasks in order.

task taskA() << {
    println "I'm taskA"
}

task taskB() << {
    println "I'm taskB"
}

task taskC() << {
    println "I'm taskC"
}

task taskAll(dependsOn:['taskA', 'taskB', 'taskC']) << {
    println 'All Done!'
}
taskB.mustRunAfter  'taskA' //these lines ensure the order of execution
taskC.mustRunAfter  'taskB'

This gives you the output:

gradle taskall
:taskA
I'm taskA
:taskB
I'm taskB
:taskC
I'm taskC
:taskAll
All Done!

BUILD SUCCESSFUL

Total time: 2.176 secs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM