From 1efebeaa984943b53e8f04fc291bb9081d9d4327 Mon Sep 17 00:00:00 2001 From: "E.G" <146701565+GlobalStar117@users.noreply.github.com> Date: Sun, 18 Jan 2026 06:29:30 +1100 Subject: [PATCH] fix: Handle -X JVM options on command line (fixes #5742) (#8566) Previously, passing JVM options like -Xmx1G directly on the command line would result in an error: sbt -v -Xmx1G [error] Expected ';' [error] -Xmx1G [error] ^ This was because -X options were being passed to sbt as commands instead of being recognized as JVM arguments. Changes: - Added handling for -X options in sbt.bat to pass them to the JVM - Updated help text to document this feature - Added integration tests for the new functionality --- .../src/test/scala/RunnerMemoryScriptTest.scala | 9 +++++++++ launcher-package/src/universal/bin/sbt.bat | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/launcher-package/integration-test/src/test/scala/RunnerMemoryScriptTest.scala b/launcher-package/integration-test/src/test/scala/RunnerMemoryScriptTest.scala index 3978c4fb3..7f2c3ffd0 100644 --- a/launcher-package/integration-test/src/test/scala/RunnerMemoryScriptTest.scala +++ b/launcher-package/integration-test/src/test/scala/RunnerMemoryScriptTest.scala @@ -74,4 +74,13 @@ object RunnerMemoryScriptTest extends verify.BasicTestSuite with ShellScriptUtil assert(out.contains[String]("-Xms111m")) assert(out.contains[String]("-Xss12m")) + // Test for issue #5742: -X options passed directly on command line + testOutput("sbt -Xmx1G directly on command line")("-Xmx1G", "-v"): (out: List[String]) => + assert(out.contains[String]("-Xmx1G")) + + testOutput("sbt -Xms512M -Xmx1G directly on command line")("-Xms512M", "-Xmx1G", "-v"): + (out: List[String]) => + assert(out.contains[String]("-Xms512M")) + assert(out.contains[String]("-Xmx1G")) + end RunnerMemoryScriptTest diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 0d47ca935..64091f484 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -547,6 +547,13 @@ if not "%g:~0,5%" == "-XX:+" if not "%g:~0,5%" == "-XX:-" if "%g:~0,3%" == "-XX" ) ) +rem handle -X JVM options (e.g., -Xmx1G, -Xms512M, -Xss4M) - fixes #5742 +if "%g:~0,2%" == "-X" ( + call :dlog [args_loop] -X JVM argument %~0 + call :addJava %~0 + goto args_loop +) + if defined sbt_new if "%g:~0,2%" == "--" ( rem special handling for -- template arguments since '=' gets parsed away on Windows for /F "tokens=1 delims==" %%a in ("%g%") do ( @@ -1098,6 +1105,8 @@ echo are prepended to the runner args echo !SBT_CONFIG! echo if this file exists, it is prepended to the runner args echo -Dkey=val pass -Dkey=val directly to the java runtime +echo -X^ pass -X^ directly to the java runtime +echo ^(e.g., -Xmx1G, -Xms512M, -Xss4M^) rem echo -J-X pass option -X directly to the java runtime rem echo ^(-J is stripped^) rem echo -S-X add -X to sbt's scalacOptions ^(-S is stripped^)