I haven't tried this... but here's an idea :)

integrationTest.doFirst {
        tasks.jettyRun.execute()
}

integrationTest.doLast {
        tasks.jettyStop.execute()
}

you can probably shorten it... and as you can see... jetty will only run if the 
integrationTest runs... so if it skips or is up-to-date, you're good.


Ken Sipe | [email protected] | blog: http://kensipe.blogspot.com



On May 17, 2011, at 10:34 PM, Glen Stampoultzis wrote:

> 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?
> 
> 
> 
> 
> 

Reply via email to