Search code examples
intellij-ideasbtrc

SBT can't read environment variables in IntelliJ


I defined a new environment variable in ~/.zshrc like that: export JVM_XMX=-Xmx2048M. I can verify that it was set correctly running export command and finding it in the list.

Now I want to use it in SBT. I've tried these two approaches:

sys.env("JVM_XMX")

sys.env.get("JVM_XMX")

But the value couldn't be found or the Option is None. Errors that I see are:

NoSuchElementException: key not found: JVM_XMX

NoSuchElementException: None.get

What I also tried was to add the variable into SBT in IntelliJ Settings. I went to Build, Execution, Deployment -> Build Tools -> sbt and set VM parameters to -DJVM_XMX=-Xmx2048M. It didn't help.

Anyone knows how to setup SBT to work with IntelliJ correctly?


Versions used:

sbt 1.2.8

IntelliJ IDEA 2019.2.1


Solution

  • As a workaround I was able to use system properties (scala.sys.SystemProperties). This works because this is the way how to find values added into SBT in IntelliJ Settings.

    Code example from build.sbt:

    sys.props.get("JVM_XMX")

    UPDATE:

    I was finally able to figure out what was the real problem. My .bashrc file was incorrectly set up (I had the variables only in .zshrc). After adding environment variables into correct rc file, the problem was fixed.