Specifying memory settings in application plugin start scripts


(Hani Suleiman) #1

How do I specify memory settings for the application plugin’s start scripts? Nothing obvious stands out in StartScripts…


(Benjamin Muschko) #2

GRADLE-1456 explains how to do this.


(Hani Suleiman) #3

I’m missing something, that issue seems to list all the ways that don’t work (and suggestions for how to make them work). Is there a quick example of how to do this?


(Benjamin Muschko) #4

Oh, I am sorry. I thought the ticket described the workaround as well. This post explains it.


(Hani Suleiman) #5

FYI, this is what I ended up doing:

startScripts {

ext.jvmOpts = “-Xmx256m”

inputs.property(“jvmOpts”, { ext.jvmOpts }) // for incremental build to work properly

doLast {

def optsEnvVar = “DEFAULT_JVM_OPTS”

unixScript.text = unixScript.text.replace("$optsEnvVar=${’""’}", “$optsEnvVar=${’”’}$ext.jvmOpts${’"’}")

windowsScript.text = windowsScript.text.replace(“set $optsEnvVar=”, “set $optsEnvVar=$ext.jvmOpts”)

}

}

This is pretty ugly though. Why can’t the build script more naturally supply JVM_OPTS (or even take it from the run config)?


(Alex Sko) #6

I heard Gradle 1.7 was supposed to have some improvement so that you don’t have to do search-and-replace. does anyone know if that was implemented?


(Luke Daley) #7

http://www.gradle.org/docs/1.7/release-notes#specify-default-jvm-arguments-for-the-application-plugin


(Alex Sko) #8

thank you. the build complains about this variable though:

$ gradle build distZip

Creating properties on demand (a.k.a. dynamic properties) has been deprecated

and is

scheduled to be removed in Gradle 2.0.

Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html

for information on the replacement for dynamic properties.

Deprecated dynamic property: “applicationDefaultJvmArgs”

on “task ‘:launcher:startScripts’”, value: “-Xmx1024m”.

here’a a part of my build.gradle script:

apply plugin:‘application’

startScripts {

applicationDefaultJvmArgs = “-Xmx1024m”

doLast {

}

}

and the JMV args don’t end up in the start scripts. what is the right way to use that new variable? I’m using Gradle 1.8.