Why do I get an java.lang.OutOfMemoryError when compiling with Clover turned on?

Q: Why do I get an java.lang.OutOfMemoryError when compiling with Clover turned on?

A: Instrumenting with Clover increases the amount of memory that the compiler requires in order to compile.To solve this problem, you need to give the compiler more memory. Increasing the memory available to the compiler depends on how you are launching the compiler:

  • If you are using the "in-process" compiler (the <javac> task with the "fork" attribute set to false), you will need to give Ant itself more memory to play with. To do this, use the ANT_OPTS environment variable to set the heap size of the JVM used to run Ant:
export ANT_OPTS=-Xmx256m
  • If you are using an external compiler (the <javac> task with the "fork" attribute set to true), you can set the memoryInitialSize and memoryMaximumSize attributes of the javac task:
<javac srcdir="${src}"
destdir="${build}"
fork="true"
memoryInitialSize="128m"
memoryMaximumSize="256m"/>
  • If you are using Intellij, increase the Maximum heap size on the Java Compiler.

Screenshot: Adjusting Heap Size in IntelliJ IDEA