2

If we want to clean, build and then run our application, we use ./gradlew clean run. run is part of the Gradle Application plugin.

What we want to achieve is to assign a certain maximum heap size to the application using run, something similar to ./gradlew clean run -Xmx1G. The result should equal running java -Xmx16G -jar /path/to/my/app.jar.

Is there a way to achieve this?


Edit: Just to make sure, I do not want to increase the build deamons's max heap but the max heap of the application that gets started by gradle.

3
  • 1
    Try applicationDefaultJvmArgs = ["-Xmx1G"] Commented Oct 3, 2017 at 11:30
  • 1
    you could set JAVA_TOOL_OPTIONS on the environment (export JAVA_TOOL_OPTIONS=-Xmx1G"), every jvm that is started by any subprocess will pick up that string and treat it as if it was specified directly in the commandline Commented Oct 3, 2017 at 11:31
  • @BenoArakelyan: Thanks, that works! Do you also know a solution where I can pass such applicationDefaultJvmArgs on the command line like ./gradlew clean run applicationDefaultJvmArgs=["-Xmx1G"]? Commented Oct 3, 2017 at 11:37

1 Answer 1

7

As reported in the Installing Gradle documentation for version 4.2.1:

Note that it’s not currently possible to set JVM options for Gradle on the command line.

What you are looking for can be achieved modifying the build.gradle script. You can do it adding this little code snippet to your build.gradle file:

tasks.withType(JavaExec) {
    jvmArgs = ['-Xmx16g']
}

If you want to configure also the initial Java heap size, add the following code:

tasks.withType(JavaExec) {
    jvmArgs = ['-Xms1g', '-Xmx16g']
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.