0

I need to tune the JVM memory by help of Gradle. I've writen settings in the gradle.properties file:

org.gradle.jvmargs=-XX:MaxMetaspaceSize=60M

but it didn't work. Then I've done it manually in an IDEA (Run>Edit Configurations...) and wrote the settings for the needed class (in VM options: field) and it works. Can we do the same by help of Gradle?

I've tried to do:

org.gradle.jvmargs=-XX:MaxMetaspaceSize=60M test1.Test

but I got the error:

Error: Could not find or load main class test1.Test

Jonas_Astley
  • 151
  • 7
  • Do you want to configure the memory of the Gradle daemon, or your own (likely forked) application? Also, I'm not sure I understand what the question title has to do with the question body. – Slaw Jul 16 '21 at 12:22
  • Added more detailes about the problem. I want to configure my own (likely forked). – Jonas_Astley Jul 16 '21 at 12:39
  • How did you run your application? If you are running it via `java` command, then gradle is not involved at all and you cannot change anything by using gradle params. – Flame239 Jul 16 '21 at 12:44
  • Also from gradle documentation: `org.gradle.jvmargs` specifies the JVM arguments used for the Gradle Daemon (i.e. gradle itself, because its written on jvm languages) , not your application. – Flame239 Jul 16 '21 at 12:45
  • If you're executing your project via the `application` plugin then you can set the `applicationDefaultJvmArgs`. See example 3 here: https://docs.gradle.org/current/userguide/application_plugin.html – Slaw Jul 16 '21 at 12:47
  • I did so, but it doesn't work: plugins { id 'application' } apply plugin: 'java' application { applicationDefaultJvmArgs = ["-XX:MaxMetaspaceSize=60M"] } – Jonas_Astley Jul 16 '21 at 14:59
  • Maybe I do sth wrong? – Jonas_Astley Jul 16 '21 at 15:00
  • @scala231 how do you run your application? – Flame239 Jul 16 '21 at 15:03
  • By help of IDEA. – Jonas_Astley Jul 16 '21 at 15:07
  • what is the actual command that is being invoked? In the `Run` window on very top you see the command, its greyed out and truncated, but if you click it will expand. – Flame239 Jul 16 '21 at 15:15
  • It runs via java command. – Jonas_Astley Jul 16 '21 at 15:27
  • Have IntelliJ delegate to Gradle. You can create a Gradle run configuration that simply executes `run` (or whatever task you need to use to execute your application). – Slaw Jul 17 '21 at 10:38

1 Answers1

1

When you run your application via IDEa, it runs the application using java ... command and gradle is not involed at all, so whatever you put in build.gradle doesn't matter.

If you want to run your app via gradle, consider using application plugin, which allows you to set jvm args. If you use Spring Boot use can use bootRun task and specify params in jvmArgs property.

Flame239
  • 1,274
  • 1
  • 8
  • 20