3

IntelliJ IDEA 2021.1 and 2021.2 leaves the Gradle Daemon running when I exit the program. I would like to know if there is a way to momentarily stop or restart the Gradle Daemon from within IntelliJ without exiting. Gradle has a lock on files that doesn't go away when simply closing IntelliJ. The only way to get it to release the lock is to run gradle --stop from the version of Gradle that is currently running. The approaches I've found so far are far less than ideal. I'll share them in case they help anyone else, but I'm hoping there's a better way.

If I manually browse to my User Home.gradle\wrapper\dists\gradle-x.y.z-all<hash>\gradle-x.y.z\bin for the version of Gradle that I know IntelliJ is using, then I can manually run that gradle command with --stop flag and it will stop the daemon. So, yeah I guess I could create a batch script for this, but the fact that it is stored in such a buried directory involving some sort of hash code, I don't really want to have to change this script for different systems.

In InteliJ IDEA, If I click the "elephant" looking button at the top of the gradle menu called "Execute Gradle Task" it brings up a command line that starts with "gradle", but it only accepts established task names, it doesn't accept "gradle --stop". It gives the error Unknown command-line option '--stop'.

As a less than ideal work around, I have copied the gradle-x.y.z folder from near the end of that path to c:\Gradle\ and I have added that version's bin folder to the PATH environment variable. So, at least, I can open up a command prompt and run gradle --stop for now. This becomes problematic when I want my default / command line accessible gradle version to be different from the project I am working on. Yeah I could create a bunch of custom batch scripts that point to all different versions. That doesn't sound like fun. I have a hard time believing that I can't do something within IntelliJ to get the currently running gradle daemon to shutdown.

BustedChain
  • 35
  • 1
  • 6
  • The Gradle Daemon - launched by IntelliJ - does cause issues sometimes. The easier way is to kill the processes via Task manager (windows) - since the can easily identified as java process with small footprint. - also for > windows 8 - they are grouped under the idea process. – PrasadU Oct 07 '21 at 00:44
  • I have looked through Task Manager several times and I have never spotted the process for Gradle. I have looked for Java a couple times and I didn't see it either. Still, though, the files I wanted to delete for a particular test I was doing were still locked until I manually killed the daemon using my work around. So, I disagree: It isn't always easily identified and easily killed via the task manager, but I will look again. Maybe I just was being impatient with the other junk that is running on this particular system that I don't have control over. – BustedChain Oct 08 '21 at 05:48

2 Answers2

11

IDE does not kill Gradle daemon, because this demon can be reused by another build, including when doing a build from the command line.

There is an action Show Gradle Daemons (you can call it from Help | Find Action action):

enter image description here

It will show you the list of Gradle daemons with the ability to stop them: enter image description here

Andrey
  • 15,144
  • 25
  • 91
  • 187
  • 1
    Thank you. If I had the rep to upvote your answer, I would do that too! Very helpful. I understand why it does it, but because it lingers it is actively causing problems for things I would like to be able to do sometimes, – BustedChain Oct 08 '21 at 05:46
0

This is a well known bug of gradle see the links bellow:

  1. https://github.com/gradle/gradle/issues/1747
  2. https://youtrack.jetbrains.com/issue/IDEA-257568?_ga=2.190143401.389233628.1693318566-557941880.1693318566&_gl=1*1fykzgd*_ga*NTU3OTQxODgwLjE2OTMzMTg1NjY.*_ga_9J976DJZ68*MTY5MzMxODU2Ni4xLjEuMTY5MzMxODY5Mi4wLjAuMA..

You can go to help menu in intellij and choose find action and then type 'show gradle daemons' and there you can stop the the daemons.

A better work around is to delete you .gradle cache directory while no java tasks are running (inkl. Intellij), delete the .gradle directory of your project and then set the 'org.gradle.daemon.idletimeout=120000' to a small amount of milliseconds, then gradle daemon will stop after beeing idle for defined amount of milliseconds