Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether you are running inside a gradle daemon

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.

like image 892
stolsvik Avatar asked Apr 24 '14 09:04

stolsvik


People also ask

How do I know if Gradle Daemon is running?

How can I find out if the gradle daemon is running? Running in terminal gradle --status will give the status of the gradle. You'll see "No Gradle daemons are running" message if there's no gradle daemon running. Otherwise, you'll see status of the daemon.

How do I run Gradle Daemon?

To enable the Daemon for a single build, you can simply pass the --daemon argument to your gradle command or Gradle Wrapper script. To your project's gradle. properties file. You can disable the Daemon for a specific build using the --no-daemon argument, or disable it for a specific project by explicitly setting org.

What is Daemon in Gradle?

When we build our project with Gradle, either by command line or by Android Studio, a long-running background process that runs the builds called Daemon is used.

How long does it take to start a Gradle Daemon?

For your first app, running it on the emulator takes a considerably long period of time. I've a decently fast machine and it took around 20-22 minutes to launch the app on the emulator.


1 Answers

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" };
like image 182
Knut Saua Mathiesen Avatar answered Oct 21 '22 06:10

Knut Saua Mathiesen