Daemon stops JVM GC thrashing, runs out of JVM memory

When attempting to build a multi-module Java project using Gradle 6.0 with more than 30 modules, the following error occurs:

Gradle Daemon started in 2 s 267 ms

> Configure project :soa-misc
"/opt/dabai/tools/jdk1.8.0_211/jre/lib/ext/"
null
Expiring Daemon because JVM heap space is exhausted
Daemon will be stopped at the end of the build after running out of JVM memory
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Daemon is stopping immediately JVM garbage collector thrashing and after running out of JVM memory

The parameters in $HOME/.gradle/gradle.properties were modified as follows:

org.gradle.jvmargs=-Xmx8096m -XX:MaxPermSize=8096m -XX:+HeapDumpOnOutOfMemoryError

However, the problem persists. What should be done to resolve it?

The issue is caused by Gradle running out of JVM heap space when attempting to build a multi-module Java project with more than 30 modules. The parameters in $HOME/.gradle/gradle.properties have been modified, but the problem persists. To resolve the issue, the following steps can be taken:

  1. Increase the amount of JVM heap space allocated to Gradle by modifying the org.gradle.jvmargs parameter in $HOME/.gradle/gradle.properties to a higher value than 8096m.

  2. Use the --no-daemon option when running Gradle to disable the Gradle daemon and run the build without it. This can help reduce the amount of memory used by Gradle.

  3. Split the multi-module project into smaller sub-projects to reduce the overall number of modules being built at once.

  4. Use a build caching solution like Gradle Enterprise or a local caching proxy to reduce the amount of work Gradle needs to do when building the project.

Note: It is recommended to try each solution one at a time to identify which one works best for the specific project being built.