We have build tasks which run integration tests on the code, which start a Tomcat server in daemon mode, run some tests, then shut it down.
An example of this would be:
task bddTest(…) {
doFirst {
System.setProperty(“spring.profiles.active”, “InMemoryAuth,MockDB”)
tomcatRun.daemon = true
tomcatRun.execute()
}
doLast {
tomcatStop.execute()
}
}
bddTest runs Cucumber via javaexec.
I’ve been told by a Gradle guru that calling .execute() on tasks directly is bad. However, getting things right without it is quite difficult - as you can’t just create several tasks and have the task which should execute them specify them via a ‘dependsOn([startTomcat, runTests, stopTomcat)’ call, as dependsOn order isn’t honored.
Here’s my next attempt:
task daemonModeBddTomcat(type: org.gradle.api.plugins.tomcat.TomcatRun, dependsOn: [compileBddTestJava, processBddTestResources, bddTestClasses]){
daemon = true
}
task bddTestCore(dependsOn: [daemonModeBddTomcat])
task bddTest(type: org.gradle.api.plugins.tomcat.TomcatStop, dependsOn: bddTestCore)
The task bddTestCore (in the second example) runs Cucumber as bddTest did in the first.
What folks are complaining about is that the task they think they’re running actually shuts down Tomcat, but it depends on the Cucumber task running before that, and Tomcat starting before that. Secondly, they think that three tasks being required to do the job vs. one task in the previous method is unwieldy.
What’s the “proper” Gradle way to do this? I know that creating the proper tasks can let the DAG do it’s thing better, but they wanted me to get “official” confirmation about that (or else start a flame war).
Thanks in advance
Douglas Bullard Nike, Inc.