I have a web app based on Jetty plugin and I want to write a profiler app that is a simple Java app that sends request to this web app. This means web app and profiler need to run at the same time. I’d like everything to be part of the same project and both launched by Gradle. But I don’t see how I can make Gradle run two tasks: if I start the web app (jettyRun), I don’t get a prompt back until it stops. If I start another instance of Gradle, it complains the build file is locked.
What you want to use is a task dependency on the task that starts the Jetty application and a ‘finalizer’ task that stops the Jetty application.
So if jettyStart starts the Jetty application, runProfiler runs the profile application and jettyStop stops the Jetty application, you would do something like:
We generally encourage people to look at the Gretty plugin instead of using the built-in Jetty plugin because it’s much better and supports newer versions of Jetty. You can accomplish the same thing with it. Here’s some documentation for it: http://akhikhl.github.io/gretty-doc/Integration-tests-support.html
Thanks for your answer. I wanted to point out a couple of best practices. See my answer above for a more idiomatic way of doing the same thing.
You shouldn’t call a task’s main action method directly. Gradle is responsible for making sure the task executes when it’s necessary. Calling the method directly might cause problems.
If you have an action that should always be performed after another action (even when that action may fail), you should use a finalizer task.