Skip to content

[2.x] fix: restore CLI precedence over .sbtopts (#8685)#8695

Merged
eed3si9n merged 3 commits intosbt:developfrom
it-education-md:fix/8685-restore-cli-opts
Feb 5, 2026
Merged

[2.x] fix: restore CLI precedence over .sbtopts (#8685)#8695
eed3si9n merged 3 commits intosbt:developfrom
it-education-md:fix/8685-restore-cli-opts

Conversation

@it-education-md
Copy link
Copy Markdown
Contributor

Fixes #8685

1. Summary

Restore command-line JVM argument precedence over .sbtopts in the launcher script and add a
regression test.

2. Problem

According to the issue, .sbtopts entries are appended after
CLI args in sbt 1.12.x, so .sbtopts JVM memory settings (e.g., -Xmx2g) override CLI --mem,
causing invalid JVM settings.

3. Reproduction

Step 1. Create tmp/.sbtopts:

-J-Xmx2g
-J-XX:ReservedCodeCacheSize=1g
-J-XX:MaxMetaspaceSize=2g
-J-Xss512m
-J-XX:+UseG1GC

Step 2. Run:

cd tmp
../sbt -d -mem 12288 -Dsbt.boot.lock=false test
Logs (Current behavior)
[addSbt] arg = '-debug'
[addMemory] arg = '12288'
[addJava] arg = '-Xms12288m'
[addJava] arg = '-Xmx12288m'
[addJava] arg = '-Xss4M'
[addJava] arg = '-XX:ReservedCodeCacheSize=512m'
[addJava] arg = '-Dsbt.boot.lock=false'
[residual] arg = 'test'
[addJava] arg = '-Xmx2g'
[addJava] arg = '-XX:ReservedCodeCacheSize=1g'
[addJava] arg = '-XX:MaxMetaspaceSize=2g'
[addJava] arg = '-Xss512m'
[addJava] arg = '-XX:+UseG1GC'
[residual] arg = 'test'
[sbt_options] declare -a sbt_options=()
[process_args] java_version = '17'
[addJava] arg = '-Dsbt.script=../sbt'
[copyRt] java9_rt = '/rt.jar'
mkdir: cannot create directory ‘’: No such file or directory
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
[addJava] arg = '-Dscala.ext.dirs='
# Executing command line:
java
-Dfile.encoding=UTF-8
-Xms12288m
-Xmx12288m
-Xss4M
-XX:ReservedCodeCacheSize=512m
-Dsbt.boot.lock=false
-Xmx2g
-XX:ReservedCodeCacheSize=1g
-XX:MaxMetaspaceSize=2g
-Xss512m
-XX:+UseG1GC
-Dsbt.script=../sbt
-Dscala.ext.dirs=
-jar
/home/bt/.cache/sbt/boot/sbt-launch/1.12.0/sbt-launch-1.12.0.jar
-debug
test

Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

4. Solution

Load sbtopts file options (dist/machine/project) into a list and prepend them to the argument
list so CLI args remain last and win. Preserve existing file priority: project > machine > dist.

5. Tests

Run with .sbtopts

../sbt -d -mem 12288 -Dsbt.boot.lock=false test
Logs (with fix)
[addSbt] arg = '-debug'
[addMemory] arg = '12288'
[addJava] arg = '-Xms12288m'
[addJava] arg = '-Xmx12288m'
[addJava] arg = '-Xss4M'
[addJava] arg = '-XX:ReservedCodeCacheSize=512m'
[addJava] arg = '-Dsbt.boot.lock=false'
[residual] arg = 'test'
[residual] arg = 'test'
[sbt_options] declare -a sbt_options=()
[process_args] java_version = '17'
[addJava] arg = '-Dsbt.script=../sbt'
[copyRt] java9_rt = '/home/user/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17/rt.jar'
[addJava] arg = '-Dscala.ext.dirs=/home/user/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17'
# Executing command line:
java
-Dfile.encoding=UTF-8
-XX:+UseG1GC
-Xms12288m
-Xmx12288m
-Xss4M
-XX:ReservedCodeCacheSize=512m
-Dsbt.boot.lock=false
-Dsbt.script=../sbt
-Dscala.ext.dirs=/home/user/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17
-jar
/home/user/.cache/sbt/boot/sbt-launch/1.12.0/sbt-launch-1.12.0.jar
-debug
test

[debug] Created transactional ClassFileManager with tempDir = /home/user/Desktop/ossbt/sbt/tmp/project/target/scala-2.12/sbt-1.0/classes.bak
[debug] About to delete class files:
[debug] We backup class files:
[debug] [zinc] IncrementalCompile -----------
[debug] IncrementalCompile.incrementalCompile
[debug] previous = Stamps for: 0 products, 0 sources, 0 libraries
[debug] current source = Set()
[debug] > initialChanges = InitialChanges(Changes(added = Set(), removed = Set(), changed = Set(), unmodified = ...),Set(),Set(),API Changes: Set())
[debug] Full compilation, no sources in previous analysis.
[debug] Created transactional ClassFileManager with tempDir = /home/user/Desktop/ossbt/sbt/tmp/project/target/scala-2.12/sbt-1.0/classes.bak
[debug] Removing the temporary directory used for backing up class files: /home/user/Desktop/ossbt/sbt/tmp/project/target/scala-2.12/sbt-1.0/classes.bak
[debug] Copy resource mappings:
[debug]
[debug] Copy resource mappings:
[debug]
[debug] Copy resource mappings:
[debug]
[debug] Created transactional ClassFileManager with tempDir = /home/user/Desktop/ossbt/sbt/tmp/target/scala-2.12/classes.bak
[debug] About to delete class files:
[debug] We backup class files:
[debug] [zinc] IncrementalCompile -----------
...

RunnerScriptTest

./sbt -Dsbt.boot.lock=false -Dsbt.build.includesbtn=false "launcherPackageIntegrationTest/testOnly example.test.RunnerScriptTest"

Scala Format Check

./sbt scalafmtAll (passed)

@it-education-md
Copy link
Copy Markdown
Contributor Author

@eed3si9n could you plz review my PR?

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@eed3si9n eed3si9n changed the title fix: restore CLI precedence over .sbtopts (#8685) [2.x] fix: restore CLI precedence over .sbtopts (#8685) Feb 5, 2026
@eed3si9n eed3si9n merged commit 12deebb into sbt:develop Feb 5, 2026
15 checks passed
@er1c
Copy link
Copy Markdown
Contributor

er1c commented Feb 6, 2026

@it-education-md Thanks! I had this on my list to look into this weekend and you completely beat me to it :)

@er1c
Copy link
Copy Markdown
Contributor

er1c commented Feb 6, 2026

@eed3si9n mind if we backport to 1.12.x ?

@er1c
Copy link
Copy Markdown
Contributor

er1c commented Feb 6, 2026

I spent some additional time studying the fix and the workflow, and I really do like this solution.

@eed3si9n
Copy link
Copy Markdown
Member

eed3si9n commented Feb 7, 2026

Yea, would you like to send a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbt bash script java memory arguments don't override .sbtopts like they did in 1.10.7

3 participants