Skip to content

[2.x] feat: Support forked console#8604

Merged
eed3si9n merged 1 commit intosbt:developfrom
calm329:feature/fork-console
Jan 25, 2026
Merged

[2.x] feat: Support forked console#8604
eed3si9n merged 1 commit intosbt:developfrom
calm329:feature/fork-console

Conversation

@calm329
Copy link
Copy Markdown
Contributor

@calm329 calm329 commented Jan 21, 2026

Fixes #1918

Summary

Implements fork in console := true as requested in #1918.

When enabled, the Scala REPL runs in a separate JVM, which allows:

  • Using Java agents (e.g., JAMM for memory profiling)
  • Setting custom java.library.path for native libraries
  • Running JavaFX/ScalaFX apps that can only initialize once per JVM
  • Avoiding JLine version conflicts between sbt and the REPL

Implementation

  • Added ConsoleMain as the entry point for the forked process
  • Used ProcessBuilder.inheritIO() to properly inherit terminal streams (critical for arrow key support)
  • Fork options like javaOptions and javaHome are passed through

Usage

Compile / console / fork := true
Compile / console / javaOptions += "-javaagent:/path/to/agent.jar"

Test plan

  • Added scripted test console/fork-console
  • Verified compilation succeeds
  • Manual testing of arrow keys in forked REPL

@calm329 calm329 force-pushed the feature/fork-console branch from 93c3009 to 341777b Compare January 21, 2026 23:20
@calm329
Copy link
Copy Markdown
Contributor Author

calm329 commented Jan 21, 2026

@eed3si9n Could you please review my pr? The failed CI check is flaky one, isn't related to my change

@eed3si9n
Copy link
Copy Markdown
Member

  • Used ProcessBuilder.inheritIO() to properly inherit terminal streams (critical for arrow key support)

You got the arrows key to work?

@calm329
Copy link
Copy Markdown
Contributor Author

calm329 commented Jan 22, 2026

  • Used ProcessBuilder.inheritIO() to properly inherit terminal streams (critical for arrow key support)

You got the arrows key to work?

Yeah, they work well

@calm329
Copy link
Copy Markdown
Contributor Author

calm329 commented Jan 22, 2026

Screen.Recording.2026-01-21.at.4.03.33.PM.mov

@eed3si9n
Copy link
Copy Markdown
Member

Nice!

@calm329
Copy link
Copy Markdown
Contributor Author

calm329 commented Jan 22, 2026

@eed3si9n Looks like all CI checks have passed

@eed3si9n
Copy link
Copy Markdown
Member

Yea, a slight conundrum is that I started making some improvements on the common parts between console and compile #8584 (like using URI instead of String), so if I merge this, I'd need to follow up with some changes afterwards. And I can't land the forked compile one because all the tests haven't passed. I can review this PR soon, if you're ok with some of the changes in this PR getting overwritten soon. The repl specific parts should mostly stay intact.

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 changed the title feat: Support fork in console task [1.x] feat: Support fork in console task Jan 25, 2026
@eed3si9n eed3si9n merged commit 9951a30 into sbt:develop Jan 25, 2026
22 of 23 checks passed
@eed3si9n eed3si9n changed the title [1.x] feat: Support fork in console task [2.x] feat: Support fork in console task Jan 26, 2026
@eed3si9n eed3si9n changed the title [2.x] feat: Support fork in console task [2.x] feat: Support forked console Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fork in 'console' task

2 participants