76

Summary

I would like to know how to kill every single gradle daemon and process running on a machine regardless of the version of gradle or the version of the daemon, but the "--kill" or "--stop" command will only stop those processes that match the same version of gradle.

Use case

My CI build box will have several gradle daemons running with different versions (because I'm a good boy that uses the wrapper to execute builds). Occasionally I will find issues with caching or incremental builds, and as a precaution I like to kill the daemons. The same is true for my development boxes, although the conflicts are more often with whichever VCS or IDE I am using.

What I am looking for

  1. I'm hoping there is a flag or property I am missing that I could pass to gradle to do this in a simple one line command, but if it's simple enough I would be ok with more.
  2. No scripting (looping, if-else etc).
  3. Killing all java processes is not acceptable.

Helpful links to the gradle docs

Disabling the Daemon

Stopping an existing Daemon

4 Answers 4

151

Under linux you may use pkill:

pkill -f '.*GradleDaemon.*'

Under windows you may use wmic:

WMIC PROCESS where "Name like 'java%' AND CommandLine like '%GradleDaemon%'" Call Terminate

PS. Why "no scripting" when it is probably the easiest solution?

2
  • 2
    I basically wanted something that would be really easy for developers on my team to remember and I needed it to be OS agnostic. I can write a script on my own, but I am (or was) hoping for something that was part of gradle (like a "--stop-all" flag). Your solution is also nice, so I could use it in a script that checks for the OS first and then executes one of those two commands, but I'm going to wait a but before accepting this as the answer.
    – Pytry
    Jan 15, 2019 at 16:01
  • The windows command doesn't work on my machine, presumably because the CommandLine argument doesn't contain the string, "GradleDaemon".
    – Cypher
    Sep 17, 2019 at 0:25
14

The gradle daemons did not disappear after 3hrs; this could be since I am running as Linux Guest in VirtualBox.

And hence, the following removes all gradle daemons but it could be "frowned upon" since it might be excessive...

  1. ./gradlew --stop to ensure all daemons are stopped

  2. delete all folders/files in .gradle folder in the project

  3. delete .gradle folder in /home/username/ Linu

  4. reboot

All daemons are gone. The next build takes a bit longer but worthwhile as do not like seeing 6 stopped daemons everytime a gradle build or even clean is started.

2
  • 1
    I think all you need to do is delete /home/username/.gradle/daemons
    – Lambart
    Nov 20, 2019 at 18:43
  • 2
    gradlew --stop worked for me. Killing Java didn't work. Feb 8, 2021 at 19:11
9

The gradle --status command will show you the process ids for each of the daemons. You can then use your OS to kill those processes.

I'm assuming this is cross-platform functionality, but this is the output on Windows:

  PID STATUS   INFO
10276 IDLE     5.4.1
14068 IDLE     5.4.1

It's a bit better than playing whack-a-mole with every java.exe process running on your system. Although it would be nice if gradle had a command that could terminate all running gradle daemons built-in.

1
  • 9
    gradle --status works the same as --stop and only lists daemons of the same version as the one you're running.
    – Fabio
    Feb 25, 2020 at 3:17
4

I have a similar problem and I made this:

  1. Go To C:\Users\"Username"\.gradle\daemon
  2. There are a Folder for each version of gradle
  3. Delete the folder of your actual running version Check with --status

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.