[2.x] fix: Handle --version in sbt 2.x project dirs (sbt#8717)

**Problem**
`sbt --version` in sbt 2.x project directories was delegated to the native client, which could try to start/connect to a server instead of printing version info.

**Solution**
Skip native-client delegation when `--version` is requested, and add runner-script tests for sbt 1.x and 2.x project variants.
This commit is contained in:
it-education-md 2026-02-13 02:45:42 -06:00
parent 6d94d6db61
commit 03351d6c56
3 changed files with 28 additions and 2 deletions

View File

@ -129,6 +129,32 @@ 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 version in this project:") ||
output.contains("sbtVersion")
)
assert(output.contains("sbt runner version:"))
assert(!output.contains("failed to connect to server"))
()
testOutput(
"sbt --version should work (sbt 2.x project)",
citestVariant = "citest2",
)("--version"): (out: List[String]) =>
val output = out.mkString(System.lineSeparator())
assert(
output.contains("sbt version in this project:") ||
output.contains("sbtVersion")
)
assert(output.contains("sbt runner version:"))
assert(!output.contains("failed to connect to server"))
()
testOutput("--sbt-cache")("--sbt-cache", "./cachePath"): (out: List[String]) =>
assert(out.contains[String]("-Dsbt.global.localcache=./cachePath"))

View File

@ -617,7 +617,7 @@ if !sbt_args_print_sbt_script_version! equ 1 (
goto :eof
)
if !run_native_client! equ 1 (
if !run_native_client! equ 1 if not defined sbt_args_print_version (
goto :runnative !SBT_ARGS!
goto :eof
)

2
sbt
View File

@ -909,7 +909,7 @@ if [[ $print_sbt_script_version ]]; then
exit 0
fi
if [[ "$(isRunNativeClient)" == "true" ]]; then
if [[ "$(isRunNativeClient)" == "true" ]] && [[ -z "$print_version" ]]; then
set -- "${residual_args[@]}"
argumentCount=$#
runNativeClient