I don’t think Gradle provides out of the box support for all of the steps you want. For the shut down sample app 1 step for example, I assume you would probably need to have the process ID of your running app 1. I don’t think there’s anything in the Gradle API that gives you that.
You might be able to put together a roll your own solution using java.lang.Process though. Possibly that together with TestKit might get you something close to what you’re after.
And, of course, there might be some non-obvious built in Gradle features that do exactly what you want which somebody else in the forum could suggest.
So scour through the docs, see what you can find and please come back and let everybody know whatever solution you eventually figure out?