We hope this snippet gives you some insight into how this can be done.
You can use the locks of the collector to run the code at the start / end of the assembly. However, for some reason, closing gradle.buildStarted does not work in milestone 3, so I replaced it with gradle.taskGraph.whenReady , which does the trick.
You can then call the runJetty task with Task#execute() (note that this API is not official and may disappear), and also run it from ExecutorService to get some asynchronous behavior.
import java.util.concurrent.* task myTask << { println "Do usual tasks here" } task runJetty << { print "Pretend we are running Jetty ..." while(!stopJetty){ Thread.sleep(100) } println "Jetty Stopped." } stopJetty = false es = Executors.newSingleThreadExecutor() jettyFuture = null //gradle.buildStarted { ... } gradle.taskGraph.whenReady { g -> jettyFuture = es.submit({ runJetty.execute() } as Callable) } gradle.buildFinished { println "Stopping Jetty ... " stopJetty = true //This is optional. Could be useful when debugging. try{ jettyFuture?.get() }catch(ExecutionException e){ println "Error during Jetty execution: " e.printStackTrace() } }
source share