12

Im looking for a way to insert a pause of few seconds between the calls of two gradle tasks.

I can use

firstTask.doLast {

.....

}

something like which can do Linux/Unix

sleep 45

Any ideas?

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
AKS
  • 16,482
  • 43
  • 166
  • 258

2 Answers2

32

First, I'd try to find a better solution than waiting for so long every time. Anyway, to delay the first task for 45 seconds, you can do:

firstTask.doLast {
    sleep(45 * 1000)
}

A good way to familiarize yourself with Groovy's core APIs is to study the Groovy JDK (also known as GDK). It's also a handy reference.

kaartic
  • 523
  • 6
  • 24
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
3

If you want to run integration tests in Tomcat, then simply use the Gradle Tomcat Plugin like this:

ext {
    tomcatStopPort = 8081
    tomcatStopKey = 'stopKey'
}

task integrationTomcatRun(type: org.gradle.api.plugins.tomcat.TomcatRun) {
    stopPort = tomcatStopPort
    stopKey = tomcatStopKey
    daemon = true
}

task integrationTomcatStop(type: org.gradle.api.plugins.tomcat.TomcatStop) {
    stopPort = tomcatStopPort
    stopKey = tomcatStopKey
}

task integrationTest(type: Test) {
    include '**/*IntegrationTest.*'
    dependsOn integrationTomcatRun
    finalizedBy integrationTomcatStop
}

test {
    exclude '**/*IntegrationTest.*'
}
Vidya
  • 29,932
  • 7
  • 42
  • 70
  • Hi Vidya, Can you provide a way to add a delay. firstTask deploys a .war in Tomcat (which is already running, so basically tomcat just takes 30-45 seconds to recycle to pick the new .war provided by the new build), i want to wait 45 seconds after that happens and before I call gradle integrationTest task (i.e. my secondTask). – AKS Jan 22 '14 at 21:35
  • Actually the one you mentioned I had that code already but all I needed was how to insert delay. Due to lot of customizations we have, I think we can't use Gradle's Tomcat Plugin but thanks for your inputs. Thanks Vidya. – AKS Jan 22 '14 at 23:12