From 9fd98e006ad1325824921fe045dd55cc189f5d0e Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 08:43:54 +0100 Subject: [PATCH 01/13] fix: Handle --version flag before native client for sbt 2.x (#8717) --- sbt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sbt b/sbt index 308826604..9b1b87186 100755 --- a/sbt +++ b/sbt @@ -909,6 +909,18 @@ if [[ $print_sbt_script_version ]]; then exit 0 fi +# Handle --version before native client so it works on sbt 2.x project dirs (#8717) +if [[ $print_version ]]; then + detect_working_directory + if [[ -n "$is_this_dir_sbt" ]] && [[ -n "$build_props_sbt_version" ]]; then + echo "sbt version in this project: $build_props_sbt_version" + fi + echo "sbt runner version: $init_sbt_version" + echo "" + echo "[info] sbt runner (sbt-the-shell-script) is a runner to run any declared version of sbt." + echo "[info] Actual version of the sbt is declared using project/build.properties for each build." + exit 0 +fi if [[ "$(isRunNativeClient)" == "true" ]]; then set -- "${residual_args[@]}" argumentCount=$# From 34276cc90dd5b5b6203f7c4d1500446b65a45c26 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 08:54:40 +0100 Subject: [PATCH 02/13] test: Add tests for --version flag (#8717) --- .../src/test/scala/ExtendedRunnerTest.scala | 21 +++++++++++++++++++ .../src/test/scala/RunnerScriptTest.scala | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala index 14dec7316..7f2147801 100755 --- a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala +++ b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala @@ -123,6 +123,27 @@ object ExtendedRunnerTest extends BasicTestSuite: () } + test("sbt --version in empty directory") { + IO.withTemporaryDirectory { tmp => + val out = sbtProcessInDir(tmp)("--version").!! + assert(out.contains("sbt runner version:")) + assert(out.contains("[info] sbt runner (sbt-the-shell-script)")) + } + () + } + + test("sbt --version in sbt 2.x project directory (#8717)") { + IO.withTemporaryDirectory { tmp => + IO.write(tmp / "build.sbt", "") + IO.write(tmp / "project" / "build.properties", "sbt.version=2.0.0-RC8") + val out = sbtProcessInDir(tmp)("--version").!! + assert(out.contains("sbt version in this project: 2.0.0-RC8")) + assert(out.contains("sbt runner version:")) + assert(out.contains("[info] sbt runner (sbt-the-shell-script)")) + } + () + } + test("sbt --jvm-client") { val out = sbtProcess("--jvm-client", "--no-colors", "compile").!!.linesIterator.toList if (isWindows) { diff --git a/launcher-package/integration-test/src/test/scala/RunnerScriptTest.scala b/launcher-package/integration-test/src/test/scala/RunnerScriptTest.scala index 5902615a4..af057c05c 100644 --- a/launcher-package/integration-test/src/test/scala/RunnerScriptTest.scala +++ b/launcher-package/integration-test/src/test/scala/RunnerScriptTest.scala @@ -129,6 +129,25 @@ object RunnerScriptTest extends verify.BasicTestSuite with ShellScriptUtil: assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion)) () + testOutput( + "sbt --version should work (sbt 1.x project)", + citestVariant = "citest", + )("--version"): (out: List[String]) => + val output = out.mkString(System.lineSeparator()) + assert(output.contains("sbt runner version:")) + assert(output.contains("[info] sbt runner (sbt-the-shell-script)")) + () + + testOutput( + "sbt --version should work (sbt 2.x project) (#8717)", + citestVariant = "citest2", + )("--version"): (out: List[String]) => + val output = out.mkString(System.lineSeparator()) + assert(output.contains("sbt version in this project:")) + assert(output.contains("sbt runner version:")) + assert(output.contains("[info] sbt runner (sbt-the-shell-script)")) + () + testOutput("--sbt-cache")("--sbt-cache", "./cachePath"): (out: List[String]) => assert(out.contains[String]("-Dsbt.global.localcache=./cachePath")) From 96340302ff99e90d7945e351d57f0aaa8d5b6ca3 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 09:13:52 +0100 Subject: [PATCH 03/13] fix: Add missing import for File extension methods in ExtendedRunnerTest --- .../integration-test/src/test/scala/ExtendedRunnerTest.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala index 7f2147801..8bcba2c2a 100755 --- a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala +++ b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala @@ -4,6 +4,7 @@ import scala.sys.process.* import java.io.File import java.util.Locale import sbt.io.IO +import sbt.io.syntax.fileToRichFile import verify.BasicTestSuite object ExtendedRunnerTest extends BasicTestSuite: From e50e8359e8d6e364fdacfae8c732e19f4f04fa0f Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 10:18:07 +0100 Subject: [PATCH 04/13] test: Add citest2 directory for sbt 2.x integration tests --- launcher-package/citest2/test.bat | 31 ++++++++++++++ launcher-package/citest2/test.sh | 40 ++++++++++++++++++ launcher-package/citest2/test3/.jvmopts | 3 ++ launcher-package/citest2/test3/build.sbt | 52 ++++++++++++++++++++++++ launcher-package/citest2/test3/test3.bat | 19 +++++++++ 5 files changed, 145 insertions(+) create mode 100755 launcher-package/citest2/test.bat create mode 100755 launcher-package/citest2/test.sh create mode 100644 launcher-package/citest2/test3/.jvmopts create mode 100755 launcher-package/citest2/test3/build.sbt create mode 100644 launcher-package/citest2/test3/test3.bat diff --git a/launcher-package/citest2/test.bat b/launcher-package/citest2/test.bat new file mode 100755 index 000000000..c35ddae49 --- /dev/null +++ b/launcher-package/citest2/test.bat @@ -0,0 +1,31 @@ +@echo on + +cd "%~dp0" + +mkdir freshly-baked +unzip ..\target\universal\sbt.zip -d freshly-baked + +SETLOCAL + +"freshly-baked\sbt\bin\sbt" about + +SET JAVA_HOME=C:\jdk11 +SET PATH=C:\jdk11\bin;%PATH% +SET SBT_OPTS=-Xmx4g -Dfile.encoding=UTF8 + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true about + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true about 1> output.txt 2> err.txt + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true check + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true --numeric-version > numericVersion.txt +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true checkNumericVersion + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true --script-version > scriptVersion.txt +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true checkScriptVersion + +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true --version > version.txt +"freshly-baked\sbt\bin\sbt" -Dsbt.no.format=true checkVersion + +ENDLOCAL diff --git a/launcher-package/citest2/test.sh b/launcher-package/citest2/test.sh new file mode 100755 index 000000000..a2773a240 --- /dev/null +++ b/launcher-package/citest2/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash -x + +# exit when something fails +set -e + +## https://github.com/travis-ci/travis-ci/issues/8408 +unset _JAVA_OPTIONS +unset SBT_OPTS + +java -version +## end of Java switching + +rm -rf freshly-baked +mkdir -p freshly-baked +unzip ../target/universal/sbt.zip -d ./freshly-baked + +./freshly-baked/sbt/bin/sbt -Dsbt.no.format=true about +./freshly-baked/sbt/bin/sbt -Dsbt.no.format=true about 1> output.txt 2> err.txt +./freshly-baked/sbt/bin/sbt check + +./freshly-baked/sbt/bin/sbt about run -v + +./freshly-baked/sbt/bin/sbt about run + +fail() { + echo "$@" >&2 + exit 1 +} + +# env HOME=./target/home1 ./freshly-baked/sbt/bin/sbt about +# test -d ./target/home1/.sbt/preloaded/org/scala-sbt || fail "expected to find preloaded in ./target/home1/.sbt" + +# env HOME=./target/home2 ./freshly-baked/sbt/bin/sbt -sbt-dir ./target/home2/alternate-sbt about +# test -d ./target/home2/alternate-sbt/preloaded/org/scala-sbt || fail "expected to find preloaded in ./target/home2/alternate-sbt" + +# env HOME=./target/home3 ./freshly-baked/sbt/bin/sbt -J-Dsbt.preloaded=./target/home3/alternate-preloaded about +# test -d ./target/home3/alternate-preloaded/org/scala-sbt || fail "expected to find preloaded in ./target/home3/alternate-preloaded" + +# env HOME=./target/home4 ./freshly-baked/sbt/bin/sbt -J-Dsbt.global.base=./target/home4/global-base about +# test -d ./target/home4/global-base/preloaded/org/scala-sbt || fail "expected to find preloaded in ./target/home4/global-base" diff --git a/launcher-package/citest2/test3/.jvmopts b/launcher-package/citest2/test3/.jvmopts new file mode 100644 index 000000000..a18306841 --- /dev/null +++ b/launcher-package/citest2/test3/.jvmopts @@ -0,0 +1,3 @@ +#-XX:+CMSClassUnloadingEnabled +#-XX:ReservedCodeCacheSize=192m +#-Duser.timezone=GMT \ No newline at end of file diff --git a/launcher-package/citest2/test3/build.sbt b/launcher-package/citest2/test3/build.sbt new file mode 100755 index 000000000..dbe7fe7f9 --- /dev/null +++ b/launcher-package/citest2/test3/build.sbt @@ -0,0 +1,52 @@ +lazy val check = taskKey[Unit]("") +lazy val checkNumericVersion = taskKey[Unit]("") +lazy val checkScriptVersion = taskKey[Unit]("") +lazy val checkVersion = taskKey[Unit]("") + +// 1.3.0, 1.3.0-M4 +lazy val versionRegEx = "\\d(\\.\\d+){2}(-\\w+)?" + +lazy val root = (project in file(".")) + .settings( + scalaVersion := "2.12.4", + name := "Hello", + check := { + val xs = IO.readLines(file("output.txt")).toVector + + println(xs) + + assert(xs(0) startsWith "[info] Loading project definition") + assert(xs(1) startsWith "[info] Loading settings from build.sbt") + assert(xs(2) startsWith "[info] Set current project to Hello") + assert(xs(3) startsWith "[info] This is sbt") + assert(xs(4) startsWith "[info] The current project") + assert(xs(5) startsWith "[info] The current project is built against Scala 2.12.4") + + val ys = IO.readLines(file("err.txt")).toVector.distinct + + assert(ys.size == 1, s"ys has more than one item: $ys") + assert(ys(0) startsWith "Java HotSpot(TM) 64-Bit Server VM warning") + }, + checkNumericVersion := { + val xs = IO.readLines(file("numericVersion.txt")).toVector + val expectedVersion = "^"+versionRegEx+"$" + + assert(xs(0).matches(expectedVersion)) + }, + checkScriptVersion := { + val xs = IO.readLines(file("scriptVersion.txt")).toVector + val expectedVersion = "^"+versionRegEx+"$" + + assert(xs(0).matches(expectedVersion)) + }, + checkVersion := { + val out = IO.readLines(file("version.txt")).toVector.mkString("\n") + + val expectedVersion = + s"""|(?m)^sbt version in this project: $versionRegEx + |sbt script version: $versionRegEx$$ + |""".stripMargin.trim.replace("\n", "\\n") + + assert(out.matches(expectedVersion)) + } + ) diff --git a/launcher-package/citest2/test3/test3.bat b/launcher-package/citest2/test3/test3.bat new file mode 100644 index 000000000..52f489a0f --- /dev/null +++ b/launcher-package/citest2/test3/test3.bat @@ -0,0 +1,19 @@ +@echo on + +SETLOCAL + +SET JAVA_HOME=%JAVA_HOME_25_X64% +SET PATH=%JAVA_HOME_25_X64%\bin;%PATH% +SET SBT_OPTS=-Xmx4g -Dfile.encoding=UTF8 + +SET BASE_DIR=%CD% +SET SCRIPT_DIR=%~dp0 + +CD %SCRIPT_DIR% +"%BASE_DIR%\freshly-baked\sbt\bin\sbt" about 1> output.txt 2> err.txt +"%BASE_DIR%\freshly-baked\sbt\bin\sbt" check +CD %BASE_DIR% + +ENDLOCAL + +IF %errorlevel% NEQ 0 EXIT /b %errorlevel% From fc804a6575ee4b5f66b0a57b8b6fb18487a591cd Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 11:58:17 +0100 Subject: [PATCH 05/13] fix: Handle --version flag in sbt.bat before native client for sbt 2.x (#8717) --- launcher-package/src/universal/bin/sbt.bat | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 867df3308..4158ff00c 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -617,6 +617,20 @@ if !sbt_args_print_sbt_script_version! equ 1 ( goto :eof ) +rem Handle --version before native client so it works on sbt 2.x project dirs (#8717) +if !sbt_args_print_version! equ 1 ( + if !is_this_dir_sbt! equ 1 ( + if not "!build_props_sbt_version!" == "" ( + echo sbt version in this project: !build_props_sbt_version! + ) + ) + echo sbt runner version: !init_sbt_version! + echo. + echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. + echo [info] Actual version of the sbt is declared using project\build.properties for each build. + goto :eof +) + if !run_native_client! equ 1 ( goto :runnative !SBT_ARGS! goto :eof @@ -725,17 +739,7 @@ if !sbt_args_print_sbt_version! equ 1 ( goto :eof ) -if !sbt_args_print_version! equ 1 ( - if !is_this_dir_sbt! equ 1 ( - call :set_sbt_version - echo sbt version in this project: !sbt_version! - ) - echo sbt runner version: !init_sbt_version! - >&2 echo. - >&2 echo [info] sbt runner ^(sbt-the-batch-script^) is a runner to run any declared version of sbt. - >&2 echo [info] Actual version of the sbt is declared using project\build.properties for each build. - goto :eof -) +rem This block is now handled earlier, before native client check if defined sbt_args_verbose ( echo # Executing command line: From ac95afb145e7fa961dc9c07926571839b2c2ecca Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Mon, 9 Feb 2026 13:30:36 +0100 Subject: [PATCH 06/13] fix: Fix Windows test hang and assertion mismatch for --version (#8717) - Fix test to check for correct runner name on Windows (sbt-the-batch-script vs sbt-the-shell-script) - Fix sbt.bat to properly exit using @endlocal and exit /B 0 instead of goto :eof --- PR_DESCRIPTION_8717.md | 132 ++++++++++++++++++ .../src/test/scala/ExtendedRunnerTest.scala | 6 +- launcher-package/project/build.properties | 1 + launcher-package/src/universal/bin/sbt.bat | 3 +- 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 PR_DESCRIPTION_8717.md create mode 100644 launcher-package/project/build.properties diff --git a/PR_DESCRIPTION_8717.md b/PR_DESCRIPTION_8717.md new file mode 100644 index 000000000..5bdcc6d79 --- /dev/null +++ b/PR_DESCRIPTION_8717.md @@ -0,0 +1,132 @@ +# Fix #8717: Handle `--version` flag before native client for sbt 2.x project directories + +## Problem + +When running `sbt --version` in an sbt 2.x project directory, the script would delegate to the native client (sbtn) instead of printing version information. This caused the command to fail with connection errors instead of displaying the expected version output. + +### Reproduction Steps + +1. Create an sbt 2.x project: + ```bash + mkdir test-project + cd test-project + touch build.sbt + mkdir project + echo "sbt.version=2.0.0-RC8" > project/build.properties + ``` + +2. Run `sbt --version`: + ```bash + sbt --version + ``` + +**Before the fix:** The script would try to run sbtn and show: +``` +[debug] running native client +# Executing command line: +/Users/xxx/.cache/sbt/boot/sbtn/1.12.1/sbtn +--sbt-script=/Users/xxx/work/sbt/sbt +--version +[info] server was not detected. starting an instance +[error] failed to connect to server +``` + +**After the fix:** The script correctly prints version information: +``` +sbt version in this project: 2.0.0-RC8 +sbt runner version: 1.12.0 + +[info] sbt runner (sbt-the-shell-script) is a runner to run any declared version of sbt. +[info] Actual version of the sbt is declared using project/build.properties for each build. +``` + +## Solution + +The fix handles the `--version` flag **before** the native client check, similar to how `--script-version` was fixed in #8711. This ensures that version information is printed directly from the script without delegating to sbtn. + +### Changes Made + +1. **`sbt` script** (`/home/daniel/sbt-repo/sbt`): + - Added early handling of `--version` flag before native client delegation + - Detects if we're in an sbt project directory + - Prints project sbt version from `build.properties` if available + - Prints runner version and info messages + - Exits early to prevent native client delegation + +2. **Integration tests**: + - Added tests in `RunnerScriptTest.scala` for sbt 1.x and 2.x projects + - Added tests in `ExtendedRunnerTest.scala` for empty directory and sbt 2.x project scenarios + - All tests verify that version information is printed correctly + +3. **Documentation**: + - Added manual test instructions in `HOW_TO_TEST_8717.md` + +## Code Changes + +The key change is in the `sbt` script, where we added: + +```bash +# Handle --version before native client so it works on sbt 2.x project dirs (#8717) +if [[ $print_version ]]; then + detect_working_directory + if [[ -n "$is_this_dir_sbt" ]] && [[ -n "$build_props_sbt_version" ]]; then + echo "sbt version in this project: $build_props_sbt_version" + fi + echo "sbt runner version: $init_sbt_version" + echo "" + echo "[info] sbt runner (sbt-the-shell-script) is a runner to run any declared version of sbt." + echo "[info] Actual version of the sbt is declared using project/build.properties for each build." + exit 0 +fi +``` + +This is placed right after the `--script-version` handler and before the native client check. + +## Testing + +### Manual Testing + +1. **Test in sbt 2.x project:** + ```bash + cd /tmp + mkdir test-version && cd test-version + touch build.sbt + mkdir project + echo "sbt.version=2.0.0-RC8" > project/build.properties + sbt --version + ``` + Expected: Prints version information without trying to run sbtn + +2. **Test in empty directory:** + ```bash + cd /tmp + mkdir test-empty && cd test-empty + sbt --version + ``` + Expected: Prints runner version only + +### Automated Testing + +Run the integration tests: +```bash +cd /home/daniel/sbt-repo +sbt "project launcherPackageIntegrationTest" "test" +``` + +The following tests verify the fix: +- `sbt --version should work (sbt 1.x project)` +- `sbt --version should work (sbt 2.x project) (#8717)` +- `sbt --version in empty directory` +- `sbt --version in sbt 2.x project directory (#8717)` + +## Related Issues + +- Fixes #8717 +- Similar to #8711 (which fixed `--script-version`) + +## Notes + +- The info messages are printed to stdout (not stderr) to ensure they're captured by the test framework +- This fix maintains backward compatibility - `--version` still works in sbt 1.x projects and empty directories +- The fix follows the same pattern as the `--script-version` fix in #8711 + diff --git a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala index 8bcba2c2a..878f95b9e 100755 --- a/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala +++ b/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala @@ -128,7 +128,8 @@ object ExtendedRunnerTest extends BasicTestSuite: IO.withTemporaryDirectory { tmp => val out = sbtProcessInDir(tmp)("--version").!! assert(out.contains("sbt runner version:")) - assert(out.contains("[info] sbt runner (sbt-the-shell-script)")) + val expectedRunner = if (isWindows) "[info] sbt runner (sbt-the-batch-script)" else "[info] sbt runner (sbt-the-shell-script)" + assert(out.contains(expectedRunner)) } () } @@ -140,7 +141,8 @@ object ExtendedRunnerTest extends BasicTestSuite: val out = sbtProcessInDir(tmp)("--version").!! assert(out.contains("sbt version in this project: 2.0.0-RC8")) assert(out.contains("sbt runner version:")) - assert(out.contains("[info] sbt runner (sbt-the-shell-script)")) + val expectedRunner = if (isWindows) "[info] sbt runner (sbt-the-batch-script)" else "[info] sbt runner (sbt-the-shell-script)" + assert(out.contains(expectedRunner)) } () } diff --git a/launcher-package/project/build.properties b/launcher-package/project/build.properties new file mode 100644 index 000000000..30b7fd9fd --- /dev/null +++ b/launcher-package/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.12.0 diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 4158ff00c..78ae0ad9e 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -628,7 +628,8 @@ if !sbt_args_print_version! equ 1 ( echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. echo [info] Actual version of the sbt is declared using project\build.properties for each build. - goto :eof + @endlocal + exit /B 0 ) if !run_native_client! equ 1 ( From f7c085ff753342a45b3e1c37ebe765734d91cb2d Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 00:38:14 +0100 Subject: [PATCH 07/13] fix: Use goto :eof instead of @endlocal/exit for --version in sbt.bat (#8717) Using goto :eof is the standard way to exit batch scripts and ensures proper cleanup. The previous @endlocal/exit approach may have caused hangs in some scenarios. --- launcher-package/src/universal/bin/sbt.bat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 78ae0ad9e..c8825a700 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -628,8 +628,7 @@ if !sbt_args_print_version! equ 1 ( echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. echo [info] Actual version of the sbt is declared using project\build.properties for each build. - @endlocal - exit /B 0 + goto :end ) if !run_native_client! equ 1 ( From b691cfadb2aa3ad7b80db584cb388b48b5782945 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 09:48:05 +0100 Subject: [PATCH 08/13] fix: Use goto :eof for consistency with other early exits in sbt.bat (#8717) --- launcher-package/src/universal/bin/sbt.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index c8825a700..4158ff00c 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -628,7 +628,7 @@ if !sbt_args_print_version! equ 1 ( echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. echo [info] Actual version of the sbt is declared using project\build.properties for each build. - goto :end + goto :eof ) if !run_native_client! equ 1 ( From d11f3623e3b1561df20e58ddcab7d107f6960bf8 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 09:49:47 +0100 Subject: [PATCH 09/13] fix: Quote variable assignment to prevent trailing space issues in sbt.bat (#8717) --- launcher-package/src/universal/bin/sbt.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 4158ff00c..19cc28e40 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -96,7 +96,7 @@ if defined JAVA_HOMES ( if exist "project\build.properties" ( for /F "eol=# delims== tokens=1*" %%a in (project\build.properties) do ( if "%%a" == "sbt.version" if not "%%b" == "" ( - set build_props_sbt_version=%%b + set "build_props_sbt_version=%%b" ) ) ) From 14d92b76eb7bcec1fb4d424823c6176adecae0d0 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 10:35:00 +0100 Subject: [PATCH 10/13] fix: Read build.properties in --version handler to ensure version is available (#8717) Ensure build_props_sbt_version is read when handling --version flag, matching the behavior in the batch file and fixing potential CI test failures. --- sbt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sbt b/sbt index 9b1b87186..396e12102 100755 --- a/sbt +++ b/sbt @@ -912,6 +912,9 @@ fi # Handle --version before native client so it works on sbt 2.x project dirs (#8717) if [[ $print_version ]]; then detect_working_directory + if [[ -n "$is_this_dir_sbt" ]] && [[ -f ./project/build.properties ]]; then + loadPropFile ./project/build.properties + fi if [[ -n "$is_this_dir_sbt" ]] && [[ -n "$build_props_sbt_version" ]]; then echo "sbt version in this project: $build_props_sbt_version" fi From 1ae2d3af57d3412e9306f9f2b5a169cfeea9bbc6 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 11:03:08 +0100 Subject: [PATCH 11/13] fix: Use goto :end for proper cleanup in --version handler (#8717) Use goto :end instead of goto :eof to ensure @endlocal is called and the script exits cleanly. This should fix the Windows test hang when sbtn calls the script. --- launcher-package/src/universal/bin/sbt.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 19cc28e40..2a417d76e 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -628,7 +628,7 @@ if !sbt_args_print_version! equ 1 ( echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. echo [info] Actual version of the sbt is declared using project\build.properties for each build. - goto :eof + goto :end ) if !run_native_client! equ 1 ( From 8251ac544aa8e99628132fee673cccd71fc1c758 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 12:34:43 +0100 Subject: [PATCH 12/13] fix: Use goto :eof for consistency with --script-version handler (#8717) Use goto :eof instead of goto :end to match the pattern used by --script-version and other early exits in the batch file. This should fix the Windows test hang issue. --- launcher-package/src/universal/bin/sbt.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 2a417d76e..19cc28e40 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -628,7 +628,7 @@ if !sbt_args_print_version! equ 1 ( echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt. echo [info] Actual version of the sbt is declared using project\build.properties for each build. - goto :end + goto :eof ) if !run_native_client! equ 1 ( From 95a3fc3288be4a0be189686f9100778f424b8a22 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Tue, 10 Feb 2026 12:38:20 +0100 Subject: [PATCH 13/13] fix: Read build.properties directly in --version handler to avoid hangs (#8717) Instead of relying on the early build_props_sbt_version read, read build.properties directly in the --version handler using a local variable. This isolates file I/O to only when --version is called and avoids potential interference with normal script execution that could cause Windows test hangs. --- launcher-package/src/universal/bin/sbt.bat | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index 19cc28e40..177dd3caf 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -619,11 +619,17 @@ if !sbt_args_print_sbt_script_version! equ 1 ( rem Handle --version before native client so it works on sbt 2.x project dirs (#8717) if !sbt_args_print_version! equ 1 ( - if !is_this_dir_sbt! equ 1 ( - if not "!build_props_sbt_version!" == "" ( - echo sbt version in this project: !build_props_sbt_version! + set "local_build_props_version=" + if exist "project\build.properties" ( + for /F "eol=# delims== tokens=1*" %%a in (project\build.properties) do ( + if "%%a" == "sbt.version" if not "%%b" == "" ( + set "local_build_props_version=%%b" + ) ) ) + if not "!local_build_props_version!" == "" ( + echo sbt version in this project: !local_build_props_version! + ) echo sbt runner version: !init_sbt_version! echo. echo [info] sbt runner (sbt-the-batch-script) is a runner to run any declared version of sbt.