How to set heap size for sbt?

前端 未结 10 1154
日久生厌
日久生厌 2020-11-29 17:38

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

  • create ForkRun clas
相关标签:
10条回答
  • 2020-11-29 17:52

    I was looking to solve a problem like this on Mac OS X with a homebrew install of SBT. If you installed SBT via homebrew, you're in the clear since the /usr/local/bin/sbt file 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 any settings you put in SBT_OPTS will stick (your -Xmx will take precedence). Furthermore, the first line of the script will execute any commands in ~/.sbtconfig if it exists so it may be a better place to put your SBT options if you are playing with them quite a bit. You won't have to source ~/.bash_profile every time you make a change to SBT_OPTS

    0 讨论(0)
  • 2020-11-29 17:52

    For SBT version 1.0.4 on Windows the default JVM settings come from sbt\conf\sbtconfig.txt file. Simply edit the values here. Change -Xmx512M to -Xmx2048M.

    This is not the only source of JVM options for SBT. Others can be found by inspecting sbt.bat. A simple way to diagnose, where do the settings come from, is by commenting out this line in batch file: @echo off.

    0 讨论(0)
  • 2020-11-29 17:53

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

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

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

    0 讨论(0)
  • 2020-11-29 17:54

    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

    0 讨论(0)
  • 2020-11-29 18:04

    If running sbt from PowerShell, set the SBT_OPTs environment variable, like so:

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

    Then run:

    sbt
    
    0 讨论(0)
  • 2020-11-29 18:05

    "sbt -mem 23000 run" works for me.

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