简体   繁体   中英

How to specify JVM options with Gradle?

I tried the org.gradle.jvmargs in gradle.properties, but it doesn't work. Specifically, I'm trying to change the GC of the JVM of my program, with Gradle. I don't care about the JVM Gradle runs on, but the one my application does.

The Gradle documentation for the Application Plugin says this:

If your application requires a specific set of JVM settings or system properties, you can configure the applicationDefaultJvmArgs property. These JVM arguments are applied to the run task and also considered in the generated start scripts of your distribution.

You should put the GC options into that property.

Note that this won't directly affect the behavior of an executable JAR if you execute it directly; ie without using the generated start scripts.


There are two other alternatives (solely!) for the case where you are running the application from Gradle.

  • The JavaExec task type allows you to set the JVM options via various properties; see the JavaExec API documentation

  • The Exec task type allows you to run an arbitrary command with arbitrary arguments. However if you use this to run a Java application, you will need to "wrangle" all of the command line options yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM