[2.x] feat: Use sbt script in BSP config instead of hardcoded Java path#8920
Merged
eed3si9n merged 1 commit intosbt:developfrom Mar 20, 2026
Merged
Conversation
Contributor
Author
|
@eed3si9n Please review this PR. I'd appreciate any feedbacks. |
eed3si9n
pushed a commit
to eed3si9n/sbt
that referenced
this pull request
Mar 23, 2026
…#8920) **Problem** sbt bspConfig writes the absolute path of the current Java binary into .bsp/sbt.json. When the user switches Java versions (via sdkman, cs java, etc.) or removes that JDK, the IDE fails to start the sbt BSP server because the hardcoded path is stale or gone. **Solution** When an sbt launcher script is available (via `sbt.script` system property or PATH lookup), generate: "argv": ["/path/to/sbt", "bsp"]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sbt bspConfigwrites the absolute path of the current Java binary into.bsp/sbt.json. When the user switches Java versions (via sdkman, cs java, etc.) or removes that JDK, the IDE fails to start the sbt BSP server because the hardcoded path is stale or gone.Solution
When an sbt launcher script is available (via
sbt.scriptsystem property or PATH lookup), generate:instead of the old direct java invocation. The sbt script resolves Java from PATH/JAVA_HOME at runtime, so switching Java versions no longer breaks BSP.
Falls back to the previous direct java invocation when no sbt script is found (e.g. when sbt is launched from an IDE without the script on PATH).
Changes
BuildServerConnection.scala- prefer sbt script asargv[0], fall back to direct javaMain.scala,NetworkClient.scala- recognize"bsp"(without dash) as a BSP commandsbt(bash) - handlebspcommand: bypass native client, pass-bspto Bootsbt.bat- handlebspcommand: bypass native clientsbtw/Main.scala- handlebspin residual args: bypass native clientTest plan
BuildServerConnectionSpec(fallback argv structure, sbtScriptInPath)BspConfigTest(accepts both sbt-script and java-direct formats)protocolProj/test- 10/10 passedcommandProj/test- 42/42 passedscalafmtCheck- all passedpublishLocalBin, created test project, ranbspConfig, confirmed.bsp/sbt.jsonuses sbt script pathsbt bspstarts and exits cleanly (exit code 0)Closes: #7245
Generated-by: Claude Opus 4.6