10

I know it may look like a duplicate of How to disable Gradle daemon in IntelliJ Idea?, but I don't want to completely disable gradle daemon. I just want to use only one daemon, not many of them.

The problem I have is that to successfully run some gradle tasks I have to give about 2GB RAM to gradle. And my system only had 8GB of memory.

The problem is that when I perform certain actions (I think it's "refresh gradle projects", there are 2 of them) - I sometiems get 2 or more gradle daemons running. Each consuming 2GB of memory.

Is it possible to use only one daemon or somehow automatically stop those extra daemons?

Community
  • 1
  • 1
barteks2x
  • 1,275
  • 12
  • 24

2 Answers2

3

You can stop all currently running daemons with gradlew --stop. New deamons are only created if necessary. If e. g. a different Java version is used or different daemon arguments are needed and so on. You could maybe look with Sysinternals ProcessExplorer and compare the two processes to find where they differ to find a reason why two are created.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • The problem seems to be caused by using 2 different gradle versions, but I have no idea why that happens. – barteks2x Apr 18 '16 at 14:31
  • After removing the second unnecessary gradle project (I previously thought it doesn't cause any issues) commandline arguments to both gradle daemons are identical. So I still don't know why it uses 2 daemons, one for "Refresh gradle projects" and one fro running gradle tasks. – barteks2x Apr 18 '16 at 14:38
  • Maybe this is because the gradle tooling API is used for refreshing the gradle project and the project gradle wrapper used to execute tasks, but I'm not sure. I would have thought if the Java versions and the arguments are identical only one daemon should be started. – Vampire Apr 18 '16 at 15:40
  • That is very likely to be the reason, but is there something I can do about it? – barteks2x Apr 18 '16 at 19:00
  • If it is, I guess not. As far as I know the tooling api can exclusively be used via daemon. Well, you could prevent your "normal" build to use the daemon. It will nevertheless start one as you configured jvm properties for memory size if I got your right, but if you explicitly disable the daemon, it will not keep running. This saves memory as the daemon will quit after the task, but the builds will be a bit slower. – Vampire Apr 18 '16 at 21:44
  • The thing I need to use gradle for is extremely slow anyway (waiting minutes to finish). So disabling daemon entirely isn't going to affect speed that much. – barteks2x Apr 19 '16 at 00:47
0

For folks ending up here with a similar but slightly different problem -- you may have different file.encoding properties. Using ProcessExplorer check the command line arguments like this answer suggests. If you have some with UTF-8 and others with the Windows one then that's your problem. This happened to me probably because I use Git for Windows and IntelliJ. I think in the git environment it defaulted to UTF-8 instead of the Windows one.

To solve this, see this document about how to change the JVM memory. Essentially, make a gradle.properties file in your Gradle home (~/.gradle/gradle.properties by default) and add this

org.gradle.jvmargs=-Dfile.encoding=UTF-8

If you already have some arguments there, just append them like so,

org.gradle.jvmargs=-Xmx1024m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8

Now you should only have one Gradle daemon! (Unless you try to start one while another is busy, of course.)

Captain Man
  • 6,997
  • 6
  • 48
  • 74