Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set heap size for sbt?

Tags:

scala

sbt

People also ask

How can I increase my SBT memory?

Increase Memory for sbt and Maven It is possible to start Maven and sbt with increased memory. We recommend you increase the Maximum Metaspace size and the Thread Stack size. These values can be set using -Xss2M -XX:MaxMetaspaceSize=1024M . The exact values may depend on your hardware and your code base.

How do I increase allocated heap size?

1)Change the gradle. properties file and change the heap size as per your requirement. 2)"Edit Custom VM Options" from the Help menu. It will open studio.


You need SBT_OPTS, here's what I use in my .bash_profile:

export SBT_OPTS="-Xmx1536M -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M  -Duser.timezone=GMT"

UPDATE: To get your 2G heap space you can use this:

export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M  -Duser.timezone=GMT"

NOTE: SBT MUST BE LATEST VERSION

Older versions of sbt contain bugs that override these settings, use brew upgrade sbt for latest sbt for Mac (assuming brew install) (IDK for Linux). https://github.com/sbt/sbt/issues/2945#issuecomment-277490848


As of March 2015, if you are using sbt on OSX with Homebrew then you should edit the file /usr/local/etc/sbtopts

e.g.

# set memory options
#
#-mem   <integer>
-mem 2048

"sbt -mem 23000 run" works for me.


I have found the solution. No matter how you specify JVM heap size, it will never work because SBT executable already has it overridden.

There is a line in SBT executable which says:

. /usr/share/sbt/sbt-launch-lib.bash

So I edited the file:

  # run sbt
  execRunner "$java_cmd" \
    ${SBT_OPTS:-$default_sbt_opts} \
-   $(get_mem_opts $sbt_mem) \
    ${java_opts} \
    ${java_args[@]} \
    -jar "$sbt_jar" \
    "${sbt_commands[@]}" \
    "${residual_args[@]}"

Remove the - line.

Now when you run SBT, it will no longer override your JVM heap size settings. You can specify heap size settings using @Noan's answer.

Or alternatively:

sbt -J-Xmx4G -J-Xms4G