Skip to content

[2.x] fix: Runner should fail on JDK < 17 for sbt 2.x#8825

Merged
eed3si9n merged 6 commits intosbt:developfrom
eureka928:fix/jdk17-check-sbt2-8813
Feb 27, 2026
Merged

[2.x] fix: Runner should fail on JDK < 17 for sbt 2.x#8825
eed3si9n merged 6 commits intosbt:developfrom
eureka928:fix/jdk17-check-sbt2-8813

Conversation

@eureka928
Copy link
Copy Markdown
Contributor

Fixes #8813

Summary

When sbt 2.x is run with JDK 8, the runner now prints a clear error message instead of the confusing "server was not detected" error.

Problem

Running sbt -Dsbt.version=2.0.0-RC9 with JDK 8 produces:

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

This happens because for sbt 2.x, isRunNativeClient() returns true by default, which skips the JDK version check entirely. The native client then fails with a confusing error.

Solution

Detect the JDK version before the native client decision in all three runner entry points, and require JDK 17+ when sbt major version >= 2:

  • Bash runner (sbt): Added checkJava17ForSbt2() function, moved java_version detection before the native client branch
  • Windows batch (sbt.bat): Updated :checkjava to parse sbt version and require 17 for sbt 2.x, moved call before native client branch
  • Windows native launcher (sbtw/Main.scala): Extracted Runner.minimumJdkVersion() helper, moved JDK check before shouldRunNativeClient

Users now see:

[error] sbt 2.x requires JDK 17 or above, but you have JDK 8

Test results

Bash function test (7 cases, all pass):

=== sbt 2.x with JDK 8 -> should fail ===
[error] sbt 2.x requires JDK 17 or above, but you have JDK 8
BLOCKED (expected)

=== sbt 2.x with JDK 17 -> should pass ===
PASS (expected)

=== sbt 1.x with JDK 8 -> should pass ===
PASS (expected)

=== sbt 2.x with JDK 11 -> should fail ===
[error] sbt 2.x requires JDK 17 or above, but you have JDK 11
BLOCKED (expected)

=== sbt 2.x with JDK 21 -> should pass ===
PASS (expected)

=== no sbt version -> should pass (no check) ===
PASS (expected)

=== init_sbt_version fallback ===
[error] sbt 2.x requires JDK 17 or above, but you have JDK 8
BLOCKED (expected)

sbtw unit tests (sbt sbtwProj/test):

[info] sbtw.RunnerSpec
[info] - minimumJdkVersion should require JDK 17 for sbt 2.x
[info] - minimumJdkVersion should require JDK 17 for sbt 2.x snapshot
[info] - minimumJdkVersion should require JDK 8 for sbt 1.x
[info] - minimumJdkVersion should require JDK 8 when version is absent
[info] - minimumJdkVersion should require JDK 17 for future sbt 3.x
[info] Passed: Total 5, Failed 0, Errors 0, Passed 5

Verification

  • sbt sbtwProj/compile passes
  • sbt sbtwProj/test — 5/5 pass
  • sbt sbtwProj/scalafmtCheck passes
  • Bash checkJava17ForSbt2 tested manually — 7/7 cases pass

**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes sbt#8813
Move JDK version check before native client decision in sbtw and
require JDK 17+ when build.properties declares sbt 2.x.
Move checkjava before native client decision in sbt.bat and require
JDK 17+ when build.properties declares sbt 2.x.
Extract JDK version check logic into Runner.minimumJdkVersion for
testability. Add RunnerSpec with tests for sbt 1.x, 2.x, and 3.x
version detection.
@eureka928
Copy link
Copy Markdown
Contributor Author

Manual test proof (before vs after)

Before (develop branch) — JDK 8 + sbt 2.x:

The sbt script's isRunNativeClient() returns true for sbt 2.x, skipping the JDK version check entirely. The native client then fails:

$ sbt -Dsbt.version=2.0.0-RC9  # with JDK 8
[info] server was not detected. starting an instance
[error] failed to connect to server

After (this branch) — JDK 8 + sbt 2.x:

The new checkJava17ForSbt2 runs before the native client decision and catches it immediately:

$ sbt -Dsbt.version=2.0.0-RC9  # with JDK 8
[error] sbt 2.x requires JDK 17 or above, but you have JDK 8

After — JDK 17 + sbt 2.x (normal operation):

$ sbt -Dsbt.version=2.0.0-RC9  # with JDK 17
(check passes, sbt proceeds normally)

After — JDK 8 + sbt 1.x (backward compatible):

$ sbt -Dsbt.version=1.10.7  # with JDK 8
(check passes, sbt proceeds normally — sbt 1.x only requires JDK 8)

Note: JDK 8 is not installed on my test machine, so the bash function was tested by simulating java_version=8 and build_props_sbt_version=2.0.0-RC9 against the extracted checkJava17ForSbt2() function (7 test cases, all pass). The sbtw Runner.minimumJdkVersion logic is covered by 5 unit tests.

@eed3si9n
Copy link
Copy Markdown
Member

FYI - we have fake java script in https://github.com/sbt/sbt/blob/develop/launcher-package/integration-test/bin/java, which returns 'openjdk version "1.8.0_212"'. You might need to bump that to JDK 17.

@eureka928
Copy link
Copy Markdown
Contributor Author

Thanks @eed3si9n — good catch. I've bumped the fake java script from JDK 8 to JDK 17 in 52c79d7 so the citest2 (sbt 2.x) integration tests won't be blocked by the new JDK version check.

The fake java script used by launcher integration tests reported
JDK 8. Since sbt 2.x now requires JDK 17+, the citest2 (sbt 2.x)
integration tests would fail with the new JDK version check.
@eureka928 eureka928 force-pushed the fix/jdk17-check-sbt2-8813 branch from 52c79d7 to 800e9cb Compare February 27, 2026 05:44
Instead of silently ignoring --rt-ext-dir (which causes sbt.bat
to mkdir on an empty string), properly simulate JDK 9+ behavior
by creating a temp directory with java9-rt-ext- prefix and a
dummy rt.jar inside it.
@eureka928
Copy link
Copy Markdown
Contributor Author

Happy Friday @eed3si9n
This is ready to go as well😉
Thank you for review and merging

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 28d877f into sbt:develop Feb 27, 2026
15 checks passed
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes sbt#8813
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes sbt#8813
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes sbt#8813

* [2.x] fix: Fail early when sbt 2.x is run with JDK < 17 (sbtw)

Move JDK version check before native client decision in sbtw and
require JDK 17+ when build.properties declares sbt 2.x.

* [2.x] fix: Fail early when sbt 2.x is run with JDK < 17 (sbt.bat)

Move checkjava before native client decision in sbt.bat and require
JDK 17+ when build.properties declares sbt 2.x.

* [2.x] test: Add minimumJdkVersion helper and unit tests for sbtw

Extract JDK version check logic into Runner.minimumJdkVersion for
testability. Add RunnerSpec with tests for sbt 1.x, 2.x, and 3.x
version detection.

* [2.x] test: Bump fake java to JDK 17 for integration tests

The fake java script used by launcher integration tests reported
JDK 8. Since sbt 2.x now requires JDK 17+, the citest2 (sbt 2.x)
integration tests would fail with the new JDK version check.

* Simulate JDK 9+ rt.jar handling in fake java script

Instead of silently ignoring --rt-ext-dir (which causes sbt.bat
to mkdir on an empty string), properly simulate JDK 9+ behavior
by creating a temp directory with java9-rt-ext- prefix and a
dummy rt.jar inside it.
eed3si9n added a commit that referenced this pull request Mar 1, 2026
**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes #8813

* [2.x] fix: Fail early when sbt 2.x is run with JDK < 17 (sbtw)

Move JDK version check before native client decision in sbtw and
require JDK 17+ when build.properties declares sbt 2.x.

* [2.x] fix: Fail early when sbt 2.x is run with JDK < 17 (sbt.bat)

Move checkjava before native client decision in sbt.bat and require
JDK 17+ when build.properties declares sbt 2.x.

* [2.x] test: Add minimumJdkVersion helper and unit tests for sbtw

Extract JDK version check logic into Runner.minimumJdkVersion for
testability. Add RunnerSpec with tests for sbt 1.x, 2.x, and 3.x
version detection.

* [2.x] test: Bump fake java to JDK 17 for integration tests

The fake java script used by launcher integration tests reported
JDK 8. Since sbt 2.x now requires JDK 17+, the citest2 (sbt 2.x)
integration tests would fail with the new JDK version check.

* Simulate JDK 9+ rt.jar handling in fake java script

Instead of silently ignoring --rt-ext-dir (which causes sbt.bat
to mkdir on an empty string), properly simulate JDK 9+ behavior
by creating a temp directory with java9-rt-ext- prefix and a
dummy rt.jar inside it.

Co-authored-by: Dream <[email protected]>
eed3si9n added a commit that referenced this pull request Mar 1, 2026
**Problem**
Running sbt 2.x with JDK 8 produces a confusing "server was not
detected" error because the JDK version check only required JDK 8+
and only ran in the non-native-client path.

**Solution**
Move java_version detection before the native client decision and add
checkJava17ForSbt2 that requires JDK 17+ when sbt major version >= 2.

Fixes #8813

Co-authored-by: Dream <[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.

[2.x] "server was not detected" (runner should fail on JDK 8)

2 participants