How to set heap size for sbt?

I am using SBT 0.12.0. I read the other stack overflow answers and followed them, however none of them help, for example:

  • create ForkRun class - I did not observe any forked process during my use of sbt
  • set the JAVA_OPTS environment JAVA_OPTS - it is set, but the sbt process command line does not seem to use it at all.
  • sbt -J-Xmx2G adds the parameter to the sbt process command line, however the old -Xmx1536m value -Xmx1536m used by sbt instead of the added parameter.

Am I missing something? How to set heap size for sbt 0.12 when running both tests and run ?

+78
scala sbt
Mar 07 '13 at 20:13
source share
10 answers

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

The SBT executable has a line that 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[@]}" 

Delete the line - .

Now when you start SBT, it will no longer override the JVM heap size settings. You can specify heap size settings using @Noan answer.

Or alternatively:

sbt -J-Xmx4G -J-Xms4G

+20
Mar 07 '13 at 23:53
source share

You need SBT_OPTS , this is 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 2G heap space you can use this:

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

NOTE: SBT SHOULD BE THE LAST VERSION

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

+89
Mar 07 '13 at 20:55
source share

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

eg.

 # set memory options # #-mem <integer> -mem 2048 
+60
Mar 16 '15 at 0:44
source share

"sbt -mem 23000 run" works for me.

+40
Jan 02 '14 at 20:16
source share

In windows for sbt 0.13.9.2 you need to set JAVA_OPTS in the jvm parameters you want.

 > set JAVA_OPTS=-Xmx1G > sbt assembly 

sbt.bat script loads the default values ​​from conf\sbtconfig.txt into CFG_OPTS , but will use JAVA_OPTS .

Relevant excerpts from sbt.bat :

 rem FIRST we load the config file of extra options. set FN=%SBT_HOME%\..\conf\sbtconfig.txt set CFG_OPTS= FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%FN%") DO ( set DO_NOT_REUSE_ME=%%i rem ZOMG (Part #2) WE use !! here to delay the expansion of rem CFG_OPTS, otherwise it remains "" for this loop. set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! ) 

., (skip).,.

 rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config. set _JAVA_OPTS=%JAVA_OPTS% if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=%CFG_OPTS% :run "%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %* 
+15
Jan 20 '16 at 15:53
source share

I was looking for a solution to this problem on Mac OS X using the SBT home installation. If you installed SBT via homebrew, you are explicit, as the file /usr/local/bin/sbt looks like

 #!/bin/sh test -f ~/.sbtconfig && . ~/.sbtconfig exec java -Xmx512M ${SBT_OPTS} -jar /usr/local/Cellar/sbt/0.12.3/libexec/sbt-launch.jar "$@" 

This means that all settings entered in SBT_OPTS will be inserted (your -Xmx will take precedence). In addition, the first line of the script will execute any commands in ~/.sbtconfig , if it exists, so it might be better to place your SBT parameters if you play with them very little. You do not have to source ~/.bash_profile every time you change SBT_OPTS

+11
Jul 02 '13 at 23:00
source share

If you are running sbt from PowerShell, set the SBT_OPTs environment SBT_OPTs , for example:

 $env:SBT_OPTS="-Xms512M -Xmx1024M -Xss2M -XX:MaxMetaspaceSize=1024M" 

Then run:

 sbt 
+6
Aug 16 '17 at 11:53 on
source share

For SBT version 1.0.4 on Windows , the default JVM settings refer to the sbt\conf\sbtconfig.txt . Just change the values ​​here. Change -Xmx512M to -Xmx2048M .

This is not the only source of JVM parameters for SBT. Others can be found by checking sbt.bat . An easy way to diagnose where the settings come from is to comment out this line in the batch file: @echo off .

+4
Dec 03 '17 at 18:04 on
source share

A quick way to do this is with the .jvmopts file in the root of your project (from the Lagom Framework documentation ):

  $ cat .jvmopts -Xms512M -Xmx4096M -Xss2M -XX:MaxMetaspaceSize=1024M 
0
Apr 16 '19 at 11:19
source share

In my case, my service configuration SBT_OPTS and JAVA_OPTS environment variables. I was able to set limits by setting the following in my build.sbt :

 javaOptions in Universal ++= Seq( "-J-Xms1g", "-J-Xmx2g") 

Link: https://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/customize.html

0
Jun 13 '19 at 19:47
source share



All Articles