5

I'm getting the following error when I build a Gradle project, but SpringToolSuite runs fine

Error occured during the initialization of VM
Could not reserve enough space for object heap
Error: Could not create Java Virtual Machine
Error: A fatal exception has occurred. Program will exit.

I have 4GB of RAM, My OS is 64-bit and I recently upgraded Java from 1.6 to 1.7

And this is my sts.ini

 -startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-product
org.springsource.sts.ide
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
1024M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx768m
-XX:MaxPermSize=1024m

I've tried all sorts of variations of -Xms and -Xmx and still the same error.

Yeshwanth Reddy
  • 51
  • 1
  • 1
  • 2
  • "Error: Could not create Java Virtual Machine" makes me think -Xmx is greater than the max allowed by the particular JVM instance. Are you sure gradle isn't running on a different JRE than you think, maybe on a 32-bit jre somewhere on your machine? – Keith Jun 25 '13 at 14:44
  • sts.ini is used only for starting STS. gradle vmargs are coming from a different place. – Andrew Eisenberg Jun 25 '13 at 19:33

4 Answers4

3

If your STS is running fine then the problem is with the JVM gradle runs to build your project.

If you're using Gradle Wrapper you can configure direct its file, if you want eclipse to override it's params than you can try editing the Gradle preferences under Window > Preferences > Gradle > Arguments with your custom values for -Xmx and -Xms.

enter image description here

mtrovo
  • 879
  • 1
  • 6
  • 15
1

You have to go to your main gradle folder where you install Gradle so if you installed Gradle in home directory ex.:

C:\Users\YourUserName\.gradle\deamon\2.1

and create there file

gradle.properties

Put into file this:

org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

org.gradle.java.home=C:/Development/Tools/Java/Java7/bin [CHANGE IT TO YOUR PATH TO JAVA_HOME]
Piotr Korlaga
  • 3,338
  • 2
  • 19
  • 28
0

I was having same kind of problem. The following solved the problem for me:

Eclipse -> run -> run configuration -> arguments

and add

-XX:MaxHeapSize=1024m

The size depends on your application's requirement. Hope this will help you. If you are using STS I think you can find the same option as of Eclipse.

Jonathan Drapeau
  • 2,610
  • 2
  • 26
  • 32
sashikanta
  • 341
  • 5
  • 19
0

In android studio I added this line:

org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
tobias_k
  • 81,265
  • 12
  • 120
  • 179