4

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

Marek J
  • 1,364
  • 8
  • 18
  • 33

3 Answers3

1

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.

Marek J
  • 1,364
  • 8
  • 18
  • 33
0

If you'd like this property to be part of your project, and not only in your solution, you can add a file names ".sbtopts" at the root of your repository, next to the build.sbt file. In this file you can configure the JVM options. For instance you can add there: -J-Xmx2048M

I couldn't find the sbt documentation supporting my suggestion, but it works for me :)

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
  • Looks like this should work for JVM options. But how to define custom environment variable? I've tried `-DCUSTOM_VARIABLE=value`, but it didn't work. – Marek J Sep 04 '19 at 13:29
0

I was able to work around this issue by going to Preferences -> Build, Execution, Deployment -> Build Tools -> sbt, then enabling sbt shell for builds and project reload.

intellij sbt shell use for settings

Snowbldr
  • 776
  • 6
  • 11