13
votes

For a project, I need to start SBT with specific JVM options (-Dfile.encoding=UTF-8 and a number of memory/gc options) - but I don't necessarily want to apply those same options to every SBT project I have.

I've seen references (in sbt-extras) to the .sbtopts (project-specific SBT command line options) and .jvmopts (project-specific SBT JVM options) files that are supposed to support this, if found in the root directory of an SBT project, but the standard Windows version of SBT (I'm using version 0.13.1) seems to ignore them.

(The sbt-extras approach appeals to me because, assuming that .sbtopts and .jvmopts are tracked in version control, there is zero SBT configuration required for people wishing to build the project.)

Is there a current mechanism to specify project-specific SBT options that works cross platform?

UPDATE: Since I originally raised this question, .sbtopts and .jvmopts are now part of the standard Linux version of SBT, and sbt-extras is no longer required. However, the Windows version only supports .jvmopts and does not recognize .sbtopts.

3
Placing options in .jvmopts and .sbtopts is an additional feature provided by sbt-extras, it is not supported by SBT itself. You should try running sbt-extras using cygwin.gourlaysama
Correction: reading .sbtopts (in the current directory) is supported by sbt. It is only .jvmopts that is added by sbt-extras. But .sbtopts is enough: you can, for example, add -J-Xmx1G so .sbtopts instead of adding -Xmx1G to .jvmopts. But you are right, the sbt.bat script doesn't read it on Windows...gourlaysama
@JacekLaskowski I meant that the standard bash runner of sbt (here: github.com/sbt/sbt-launcher-package/blob/master/src/universal/… ) does read the content of .sbtopts, but sadly the Windows runner doesn't. Even though it is a shell script, it is definitely packaged with SBT (0.13) itself.gourlaysama
It begs a pull request then ;-)Jacek Laskowski
Correction to @gourlaysama's correction: BOTH .sbtopts & .jvmopts are supported since 1.3.14 (anno 2016) and mentioned in the updated question. I didn't read the update before writing this comment, so if you are reading this, you too have probably not read the update! 😄conny

3 Answers

4
votes

This is a recognized limitation with the current version of SBT (v1.0.3, at the time of writing) on Windows (it doesn't recognize .sbtopts in the project's root directory). All versions now support the .jvmopts file.

You can track the status of this issue on sbt-launcher-package's _GitHub issue tracker.

UPDATE: This issue was fixed in Oct. 2019. Thanks to @conny for pointing that out.

0
votes

It appears the sbt-launcher-package project (under the sbt projects umbrella that adds some certainty) is the way to follow.

-1
votes

You can change JVM options from your build configuration. As an example:

fork in run := true

javaOptions += "-Xmx1G"

The fork option is important because sbt needs to start a new JVM when you execute the run task, otherwise options won't be applied to the currently running one.

This explanation assumes that you are using an sbt-style build; if you are using a Scala-based build (that is what I actually use) you should write it as:

lazy val yourProject = Project(id = "some-project-id", base = file("./"),
  settings = Project.defaultSettings ++ Seq(
    fork in run := true,
    javaOptions += "-Xmx1G"
    // ...
  ))