Skip to content

[2.x] fix: Allow ++ command to accept projects not in current state#8505

Merged
eed3si9n merged 1 commit intosbt:developfrom
MkDev11:fix/switch-command-project-parsing-7574
Jan 13, 2026
Merged

[2.x] fix: Allow ++ command to accept projects not in current state#8505
eed3si9n merged 1 commit intosbt:developfrom
MkDev11:fix/switch-command-project-parsing-7574

Conversation

@MkDev11
Copy link
Copy Markdown
Contributor

@MkDev11 MkDev11 commented Jan 13, 2026

Fix: Allow ++ command to work with projects that don't exist yet

Problem

When you run sbt '++2.12.19 docs/publishSite', it fails with "Project not found" if the docs project only exists after switching to Scala 2.12.19.

The workaround has been to use a semicolon to separate commands: sbt '++2.12.19; docs/publishSite'. This works because the semicolon forces sbt to execute the version switch first, then parse the second command in the new state where docs exists.

Solution

The parser now accepts project/task patterns even when the project isn't available in the current state. It works like this:

  1. First, try to parse the command normally using state.combinedParser (validates against current project structure)
  2. If that fails, fall back to accepting any project/task pattern using a simple slash-delimited parser
  3. The command validation happens later during execution, after the Scala version switch completes

By the time the command actually runs, the project exists in the new Scala version's state.

Implementation

Added a slashCommand fallback parser that matches project/task patterns:

val slashCommand = (NotSpace ~ ('/' ~> any.+)).map { case p ~ c => p + "/" + c.mkString }
val commandParser = state.combinedParser | slashCommand
val optionalCommand = Parser.opt(token(Space ~> matched(commandParser)))

The fix is targeted to only accept slash-delimited patterns, which avoids interfering with other parser components like the -v verbose flag.

Testing

The fix passes the existing actions/cross-advanced scripted test, which includes various cross-build scenarios with project-scoped commands.

Fixes #7574


Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=94194147

@MkDev11 MkDev11 force-pushed the fix/switch-command-project-parsing-7574 branch from 18986ac to 2c523c3 Compare January 13, 2026 00:32
…nt state

When using '++version project/task', the parser now accepts project/command
patterns (e.g., 'docs/docusaurusPublishGhpages') even if the project doesn't
exist in the current state. This is achieved by adding a fallback parser
that accepts any 'project/command' pattern alongside the combinedParser.

Previously, '++2.12.19 docs/task' would fail with 'Project not found' if
'docs' project wasn't available in the current Scala version, but
'++2.12.19; docs/task' worked. Now both syntaxes work correctly.

The fix is targeted to only accept slash-delimited patterns, avoiding
interference with other parser components like the -v verbose flag.

Fixes sbt#7574
@MkDev11 MkDev11 force-pushed the fix/switch-command-project-parsing-7574 branch from 2c523c3 to e0c1b17 Compare January 13, 2026 01:33
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Jan 13, 2026

let me know if you have any feedback for me

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 fix: Allow ++ command to accept projects not in current state [2.x] fix: Allow ++ command to accept projects not in current state Jan 13, 2026
@eed3si9n eed3si9n merged commit 847703c into sbt:develop Jan 13, 2026
14 checks passed
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.

Project not found when running with ++scalaVersion

2 participants