Mike Allen
Mike Allen

Reputation: 8279

Project-specific SBT JVM options

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.

Upvotes: 14

Views: 10572

Answers (3)

Mike Allen
Mike Allen

Reputation: 8279

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.

Upvotes: 4

Jacek Laskowski
Jacek Laskowski

Reputation: 74709

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

Upvotes: 0

Aldo Stracquadanio
Aldo Stracquadanio

Reputation: 6237

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"
    // ...
  ))

Upvotes: 0

Related Questions