How to prevent java.lang.OutOfMemoryError: PermGen space at Scala compilation?

前端 未结 8 1730
感动是毒
感动是毒 2020-12-02 07:36

I have noticed a strange behavior of my scala compiler. It occasionally throws an OutOfMemoryError when compiling a class. Here\'s the error message:

[info]          


        
相关标签:
8条回答
  • 2020-12-02 08:08

    I am building with the Jenkins sbt plugin and had the same problems. They were resolved after copying the SBT_OPTS from the sbt file to the Jenkins job config's JVM flags.

    0 讨论(0)
  • 2020-12-02 08:16

    I assumed you're using sbt 0.13.6 or higher. Create .sbtopts file in your sbt project's root with the following content:

    -J-Xmx4G
    -J-XX:MaxMetaspaceSize=1G
    -J-XX:MaxPermSize=1G
    -J-XX:+CMSClassUnloadingEnabled
    

    MaxMetaspaceSize is for Java 8 whereas MaxPermSize is for Java 7. They are critical to prevent out of memory errors related either to permgen or metaspace exhaustion. Of course, consider adapting flag values or adding any other flags required.

    More details and alternative approaches can be found in this blog post.

    0 讨论(0)
提交回复
热议问题