9

When I set GRADLE_OPTS or JAVA_OPTS, these are set for GradleWrapperMain when I run ./gradlew build for my project. But I need them to be set for GradleWorkerMain as well.

How do I do that?

Here's the ps listing when that Gradle job is running in Bamboo. My JAVA_OPTS (such as -Dcool.opt=1) is missing from GradleWorkerMain.

53854 ? Sl 2:13 /home/apps/jdk7/bin/java -Dorg.gradle.daemon=false -Dcool.opt=1 -Xms1g -Xmx8g -XX:PermSize=256m -XX:MaxPermSize=768m -Djava.security.egd=file:/dev/./urandom -Dorg.gradle.appname=gradlew -classpath /path/to/gradle/wrapper/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain build
54272 ? Sl 0:19 /home/apps/jdk1.7.0_45/bin/java -Dfile.encoding=ISO-8859-1 -cp /path/to/lots/of/jars.jar org.gradle.process.internal.launcher.GradleWorkerMain
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
neu242
  • 15,796
  • 20
  • 79
  • 114
  • Why do you need this? Which bigger problem are you trying to solve? Can you give a concrete example? – Peter Niederwieser Feb 20 '14 at 16:20
  • The reason is rather stupid in my case: GradleWorkerMain processes sometimes hang on my build server. I'd like to have something to grep for when I kill it. I can't just kill all GradleWorkerMain processes since this is a shared build server. So a `-Dbamboo.buildKey=${bamboo.buildKey}` would do the trick. – neu242 Feb 21 '14 at 08:33

3 Answers3

10

There is no direct way to set JVM options for a GradleWorkerMain process. Most (but not all) task types that fork new workers implement JavaForkOptions, so you could try:

tasks.withType(JavaForkOptions) {
    systemProperty "cool.opt", "1"
    jvmArgs "someArg"
}

Task types that don't implement JavaForkOptions typically allow to set fork options in some other way. For example:

tasks.withType(JavaCompile) {
    options.fork = true // otherwise won't fork
    options.forkOptions.jvmArgs = ["-Dcool.opt=1"]
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
2

One similar issue I've seen is with the gradle scala plugin. I needed to add the config below to control the Xmx.

tasks.withType(ScalaCompile) {
    configure(scalaCompileOptions.forkOptions) {
        memoryMaximumSize = '1g'
    }
}
PJ Fanning
  • 953
  • 5
  • 13
0

You can control it with:

test {
    maxHeapSize = "4g"
}
Tou Hat
  • 49
  • 5