barteks2x
barteks2x

Reputation: 1365

How to force Intellij IDEA to use only one gradle daemon?

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?

Upvotes: 10

Views: 6144

Answers (2)

Captain Man
Captain Man

Reputation: 7765

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.)

Upvotes: 0

Vampire
Vampire

Reputation: 38734

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.

Upvotes: 3

Related Questions