Glen Stampoultzis
2011-05-18 03:34:08 UTC
Hi,
I have a little problem with getting a task to run after execution of
another task. In this case I have a task called integrationTest. What I
want to do is use the Jetty plugin to execute the jettyRun task before
running the integrationTest task and to run jettyStop task after it has
finished.
integrationTest.dependsOn(jettyRun) lets me easily start the jetty server
but there doesn't seem to be a good way of hooking in jettyStop at the end.
Using integrationTest.doLast { jettyRun.execute() } lets me hook in an
action at the end of the execution chain but this suffers from a couple of
problems. Firstly if integrationTest is up-to-date then the actions aren't
run so the server doesn't stop. Secondly executing a task this way seems
to be non-standard (execute is a private API).
I found a solution to the first problem with the following code:
gradle.taskGraph.afterTask { Task task, TaskState state ->
if (task.name == 'integrationTest') {
jettyStop.execute();
}
}
but this still suffers from the second issue. Is there a clean way do this?
I have a little problem with getting a task to run after execution of
another task. In this case I have a task called integrationTest. What I
want to do is use the Jetty plugin to execute the jettyRun task before
running the integrationTest task and to run jettyStop task after it has
finished.
integrationTest.dependsOn(jettyRun) lets me easily start the jetty server
but there doesn't seem to be a good way of hooking in jettyStop at the end.
Using integrationTest.doLast { jettyRun.execute() } lets me hook in an
action at the end of the execution chain but this suffers from a couple of
problems. Firstly if integrationTest is up-to-date then the actions aren't
run so the server doesn't stop. Secondly executing a task this way seems
to be non-standard (execute is a private API).
I found a solution to the first problem with the following code:
gradle.taskGraph.afterTask { Task task, TaskState state ->
if (task.name == 'integrationTest') {
jettyStop.execute();
}
}
but this still suffers from the second issue. Is there a clean way do this?