Skip to content

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

Merged
eed3si9n merged 3 commits intosbt:developfrom
it-education-md:fix/8717-handle-version-flag
Feb 13, 2026
Merged

[2.x] fix: handle --version in sbt 2.x project dirs (sbt#8717)#8735
eed3si9n merged 3 commits intosbt:developfrom
it-education-md:fix/8717-handle-version-flag

Conversation

@it-education-md
Copy link
Copy Markdown
Contributor

Fixes #8717

Summary

In this PR,

  • fixed sbt --version behavior in sbt 2.x project directories
  • stabilized related integration tests.

Reproduction

1. Make a sbt 2.x project

cd /tmp
mkdir hello
cd hello
touch build.sbt
mkdir project
echo "sbt.version=2.0.0-RC8" > project/build.properties

2. Manual check

$HOME/XXX/sbt/sbt --version -v

Output:

[sbt_options] declare -a sbt_options=()
[debug] running native client
# Executing command line:
/home/XXX/.cache/sbt/boot/sbtn/1.12.1/sbtn
--sbt-script=/home/icodex/Desktop/ossbt/sbt/sbt
--version
-v

[info] server was not detected. starting an instance
[error] failed to connect to server

Problem

In sbt 2.x project directories, --version was being routed to the native client (sbtn) instead of being handled directly by the runner script.

Solution

Handle --version before native-client delegation.
When --version is present, skip sbtn and run the runner’s direct version-print path.

Test

Manual check

cd /tmp/hello
$HOME/XXX/sbt/sbt --version -v

Output:
[sbt_options] declare -a sbt_options=()
[process_args] java_version = '17'
[copyRt] java9_rt = '/home/XXX/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17/rt.jar'
sbt version in this project: 2.0.0-RC8
sbt runner version: _to_be_replaced

[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.

Related test hardening for CI

  • Make RunnerScriptTest assertions robust to valid output variants while keeping regression guard.
  • Harden Windows :set_sbt_version parsing by validating version-shaped tokens with fallback.
  • Replace destructive clean in ClientTest three-command success test with a non-destructive sequence.

**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.
**Problem**
Runner/client integration tests had CI-only instability from duplicated assertions and a destructive three-command test path.

**Solution**
Refactored version assertions in RunnerScriptTest and replaced the destructive `clean` sequence in ClientTest with a stable non-destructive three-command success path.
**Problem**
Windows batch parsing for `sbtVersion` used a fragile token extraction that could capture non-version tokens from noisy output.

**Solution**
Updated `:set_sbt_version` to select and validate version-shaped tokens and fallback to `build_props_sbt_version` when parsing is noisy.
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!

@eed3si9n eed3si9n merged commit 0cae584 into sbt:develop Feb 13, 2026
15 checks passed
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Feb 14, 2026
)

**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.
eed3si9n added a commit that referenced this pull request Feb 14, 2026
…8739)

**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.

Co-authored-by: Pluto <[email protected]>
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 --version doesn't work on sbt 2.x project directories

2 participants