How do I set the vm arguments for a packaged application built by distZip?

I’m using the distZip task in the Application plugin to build a packages java/groovy application. It includes a definition for a env var DEFAULT_JVM_OPTS which is passed to the JVM that runs the application. I want to pass some specific default arguments in this var - but I can see no way to set it. I’ve tried editing scripts/ but - of course - it’s overwritten.

What do I put in my build file to set this env var in the generated scripts ?

There is currently no built in support to define default opts in your build. but you can manipulate the generated build scripts within your buildscript to achieve your needs. You can either manipulate the generated start script file directly like in the following example:

startScripts{
 doLast{
  unixScript.text = unixScript.text.replace('DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="MYDEFAULT=BLA"')
  }
}

or you manipulate the scripts during the distZip task by using an according filter within your copyspec.

regards, René

Thanks Rene. That’s clear. I just looked at the source and see that the Unix template text is fixed. Presumably there is a similar fix for the Windows script, also?

The templates are adapted using the GroovyTemplateEngine. At the moment we do not offer a way to pass default OPTS to the template engine that are integrated in the resulting start script. you can access the windows start script via:

startScripts{
    doLast{
        windowsScript.text = ...
    }
}

have a look at the javadoc of CreateStartScripts task at http://gradle.org/docs/current/groovydoc/org/gradle/api/tasks/application/CreateStartScripts.html

Got it. Many thanks !

Sorry guys. I am responding very old thread.

I found a simpler way of setting up DEFAULT_JVM_OPTS.

Just add following line -

applicationDefaultJvmArgs = ["-Xms256M","-Xmx1560M"]