IDEA + Gradle + Run

Kategorie

  • IDEA Intellij
  • Gradle Project
  • Run Project via Gradle Run
  • Memory -Xmx -Xms arguments

Problem

You’re coding with IDEA and some kind of Gradle project. You would like to start your program direct out from the IDEA by using gradle run.

If your program now throw a memory exception, and you need more memory to your process.

How to tell the Gradle process to add more memory to your application.

What you want

You will add -Xmx64g -Xms256m to your applications Java VM, that start by Gradle, that start by IDEA

What is not working

  • Edit IDEA VM Optionen
  • Edit Project configuration
  • Windows and JVM_ARGS environment

What really happen

The IDEA memory configuration is configured by the VM options, fine. But these are not used while IDEA start the Gradle process. IDEA will use the project configuration arguments, while it stat the Gradle process. But this will still not help, because Gradle will start another Java VM to run your application. And the arguments that IDEA uses for Gradle aren’t copied to the Java VM for your application.

For sure, they are special arguments for Gradle, to solve this, but these locks ugly, and they aren’t helpful if you start Gradle outside the IDEA.

Solution

The only solution that works in all cases, means inside or outside the IDE, is to tell Gradle how to start your application inside the project file of Gradle.

Add this line into the build.gradle:

applicationDefaultJvmArgs = ["-Xms256m", "-Xmx96g"]

and all problems are gone