2

I'm trying to run a build task with Gradle on Jenkins, but Gradle fails to run.

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.

Parameter -Xmx2048m is apparently used in Java to run Gradle process. If this parameter is the problem, where should I change it? (Jenkins is configured for -Xmx1024m). I'm running it on device with 1GB RAM (about 700 - 500MB free before running the task).

Full log: http://pastebin.com/BBsjp5pZ

trincot
  • 317,000
  • 35
  • 244
  • 286
david8
  • 444
  • 9
  • 23
  • Can you list what all have you tried? – ND27 Jun 03 '16 at 19:41
  • @ND27 changing heap size of Jenkins in config, trying Gradle with or without deamon, different version of Gradle (latest rc and now 2.10), Gradle wrapper vs Gradle installed by Jenkins, freeing up RAM – david8 Jun 03 '16 at 19:43
  • I don't think you'd want to allocate 2GB to Java when the machine only has 500MB free. That would be expected to lead to your build eating more memory than the machine has available, which might be causing yuor crash. In general, I'd advise against running Jenkins on such a tiny machine. If you have to, try allocating *less* memory to gradle, it might work better. But it's likely to crash with a full stack if your build is large. – Jolta Jun 04 '16 at 08:03
  • Possible duplicate of [Java Refuses to Start - Could not reserve enough space for object heap](http://stackoverflow.com/questions/1058471/java-refuses-to-start-could-not-reserve-enough-space-for-object-heap) – Jolta Jun 04 '16 at 08:07
  • @Jolta Problem is I don't know how to change JVM parameres of Gradle process in Jenkins – david8 Jun 04 '16 at 10:12

2 Answers2

5

I had to modify gradle.properties file in project folder

Original settings:

org.gradle.jvmargs=-Xmx2048m

New settings:

org.gradle.jvmargs=-Xmx512m -Xms100m

References:

Where should I put gradle.properties in Jenkins https://docs.gradle.org/current/userguide/build_environment.html

david8
  • 444
  • 9
  • 23
  • While not a bad solution per se, this will impact the build on other servers than the Jenkins host, which might have more available memory. See Jayan's answer for an alternative solution which only takes local effect on the Jenkins host. – Jolta Jun 07 '16 at 11:39
  • @Jolta Jayan's answer wasn't woking for me, but there is a way to make `gradle.properties` work per machine, not per project – david8 Jun 07 '16 at 12:00
  • Nice, finely this helped me. Thanks – Surendar D May 03 '19 at 08:50
2

The Jenkins manual talks about "GRADLE_OPTS".

Gradle build steps You can set the -Xmx or -XX:MaxPermSize by adding a GRADLE_OPTS global environment variable in the Jenkins global configuration. To do this, click Manage Jenkins, then Configure System. In the Global properties section, click the Environment Variables checkbox, then add a new environment variable called GRADLE_OPTS with the value set appropriately, similar to the screen shot above regarding MAVEN_OPTS

Jayan
  • 18,003
  • 15
  • 89
  • 143