user2832649
user2832649

Reputation: 11

how to always run gradle task B after task A

Anyone knows how to get B to always run after A even if I only use 'gradle A' on the command line? My first thought was that I could use mustRunAfter, but that seems to require me to specify B on the command line.

task A << {
    println 'A'
}

task B << {
    println 'B'
}

Upvotes: 1

Views: 401

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123996

The (only) way to do so (not counting hacks) is A finalizedBy B. Note that this will run B even if A failed.

Upvotes: 4

AKS
AKS

Reputation: 17366

You need to use dependsOn feature in Gradle task.

For ex: If you run "gradle ohohWorldTask", it'll always calls myHelloTask to echo "hello" first.

// Say hello
task myHelloTask() << {
   println "hello"
}


// Say world
//task ohohWorldTask( dependsOn: [ myHelloTask ] ) << {
//or - using the above you can specify multiple tasks comma separated within [ aTask, bTask, cTask ]

task ohohWorldTask( dependsOn: myHelloTask ) << {
  println "-- World!"
}

Upvotes: -2

Related Questions