Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default jvm args to gradle application plugin?

Tags:

gradle

I use the gradle application plugin to generate the application folder. The installApp task provides a start script for me, but I have no idea how to set the jvm args from build.gradle.

Some jvm args I needed, such as file.encoding. I just modify the start script to set the DEFAULT_JVM_OPTS variable

#!/usr/bin/env bash

##############################################################################
##
##  MuzeeS3Deployer start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and MUZEE_S_DEPLOYER_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=" -Dfile.encoding=utf-8 "

If the args not set, my console cannot show messages well:

qty:MuzeeS3Deployer qrtt1$ ./build/install/MuzeeS3Deployer/bin/MuzeeS3Deployer d
2012/10/14 #U###12:02:03 SyncCommand main
ĵ#i: no aws credentials found at /Users/qrtt1/AwsCredentials.properties

When I set the encoding:

qty:MuzeeS3Deployer qrtt1$ ./build/install/MuzeeS3Deployer/bin/MuzeeS3Deployer d
2012/10/14 下午 12:04:19 SyncCommand main
警告: no aws credentials found at /Users/qrtt1/AwsCredentials.properties

I got the solution from @Peter. Finally, I make a minor changes to the scripts:

startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
        windowsScript.text = windowsScript.text.replace('DEFAULT_JVM_OPTS=', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
    }
}
like image 639
qrtt1 Avatar asked Oct 14 '12 04:10

qrtt1


People also ask

How do you pass JVM arguments in Gradle?

Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.

What is Gradle JVM option?

Basically, Gradle JVM equals Project SDK. If the project's SDK equals JRE then IntelliJ IDEA will use the same steps as in opening an existing Gradle project. If there is a Gradle wrapper, then IntelliJ IDEA will use the most compatible existing Gradle version on the machine.


2 Answers

Support for JVM arguments was added in Gradle 1.7: https://docs.gradle.org/current/userguide/application_plugin.html#configureApplicationDefaultJvmArgs

For example, for setting file.encoding, you can do:

applicationDefaultJvmArgs = ['-Dfile.encoding=utf-8']
like image 142
Alex Avatar answered Sep 26 '22 02:09

Alex


There is currently no special support for setting DEFAULT_JVM_OPTS. However, you can do something like:

startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
    }
}

You may want to do something similar for windowsScript.

like image 41
Peter Niederwieser Avatar answered Sep 23 '22 02:09

Peter Niederwieser