Gradle runs out of memory when running on jenkins

Gradle runs out of memory when running on jenkins. There is no way of specifying the memory-limit using -Xmx… as gradle does this by itself. The GRADLEOPTS environ-variable is not used in all cases (i think).

Starting process ‘Gradle Worker 1’. Working directory: /data/jenkins-slave-workspace/override-overlay - overlay-service - Integration TESTS Command: /usr/java/jdk1.7.0_40/bin/java -Dfile.encoding=UTF-8 -cp /home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/gradle-base-services-1.11.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/gradle-core-1.11.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/gradle-cli-1.11.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/gradle-native-1.11.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/gradle-messaging-1.11.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/slf4j-api-1.7.5.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/logback-classic-1.0.13.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/logback-core-1.0.13.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/jul-to-slf4j-1.7.5.jar:/home/jenkins-slave/.gradle/wrapper/dists/gradle-1.11-bin/4h5v8877arc3jhuqbm3osbr7o7/gradle-1.11/lib/guava-jdk5-14.0.1.jar org.gradle.process.internal.launcher.GradleWorkerMain Successfully started process ‘Gradle Worker 1’ Error occurred during initialization of VM java.lang.OutOfMemoryError: unable to create new native thread Could not write standard input into: Gradle Worker 1. java.io.IOException: Broken pipe

at java.io.FileOutputStream.writeBytes(Native Method)

at java.io.FileOutputStream.write(FileOutputStream.java:345)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)

at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:50)

at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:724) :storage-internalapi:compileGroovy FAILED

Apparently it’s the ‘compileGroovy’ task that’s running out of memory. See ‘GroovyCompile’ in the Gradle Build Language Reference for how to give it more memory.

The compilation of groovy is done by different workers (on other machines). When restarting the jenkins-process the problem disappeared. Are you sure that the problem occurs in the worker-processes doing the compile and not in the jenkins-task ? I will try your solution anyway.