How to prevent java.lang.OutOfMemoryError: PermGen space at Scala compilation?
The explanation for OutOfMemoryError: PermGen space is that it does not have enough permanent generation space. When we areusing Oracle JVM, There will be a need to add the -XX:MaxPermSize=256M (or some other amount of space) argument to your sbt script. For other JVMs, look at their documentation.
When we are using sbt 0.13.6 or higher. The .sbtopts file is created in your sbt project’s root with the following content:
-J-Xmx4G -J-XX:MaxMetaspaceSize=1G -J-XX:MaxPermSize=1G -J-XX:+CMSClassUnloadingEnabled
Here the MaxMetaspaceSize is for Java 8 whereas MaxPermSize is for Java 7. They are critical to avoid out of memory errors related either to permgen or metaspace exhaustion. By assuming, adapting flag values or adding any other flags required.