On 18/05/2011, at 2:13 PM, Glen Stampoultzis wrote:

> Thanks, that seems to work fairly well.  I had thought doFirst just adds the 
> action to the start of the action queue rather than executing before the task 
> itself but obviously that was an incorrect assumption.
> 
> It still leaves me with the smaller issue of using a non-public API to 
> execute the tasks but I guess I can live with that.

There are a couple of other downsides to this approach.

We do want to add some way to solve this problem, as it's a pretty common one. 
One option we've discussed is to allow you to declare 'initializer' and 
'finalizer' tasks for a given task. An initializer is a task which must run 
before the main task (like a dependency) and which is run only if the main task 
will be run. So, for example, jettyRun would be skipped if the integration 
tests are up-to-date. A finalizer is a task which must run after the main task, 
whether the main task succeeds or fails, and which is automatically added to 
the dag when the main task is added.


> 
> 
> On 18 May 2011 13:43, Ken Sipe <[email protected]> wrote:
> 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?
>> 
>> 
>> 
>> 
>> 
> 
> 


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply via email to