We have a situation where we take up a Jetty instance inside the VM that runs gradle.
However, this fails pretty badly when we are running inside a gradle daemon: We don't get rid of the Jetty instance totally, so it have to die with the gradle process itself. (However, that is not really of a big concern, since we do not want the gradle daemon in this CI integration tests case anyway).
So, we would like to know whether the current task is running inside a gradle daemon, or not - so that we can throw an exception or otherwise inform the user that this is the wrong approach, please run this un-daemonized.
Gradle names one of its thread "Daemon thread" so if you allow a hack, this could work:
def isDaemon = Thread.allStackTraces.keySet.any { it.name.contains "Daemon" };