Skip to content

[2.x] fix: extraProjects with auto-root aggregate breaks key aggregation#8690

Merged
eed3si9n merged 6 commits intosbt:developfrom
bitloi:fix/4947-extra-projects-aggregate
Feb 5, 2026
Merged

[2.x] fix: extraProjects with auto-root aggregate breaks key aggregation#8690
eed3si9n merged 6 commits intosbt:developfrom
bitloi:fix/4947-extra-projects-aggregate

Conversation

@bitloi
Copy link
Copy Markdown
Contributor

@bitloi bitloi commented Feb 4, 2026

Closes #4947

What was wrong

When a plugin adds projects via extraProjects, sbt creates an auto root that aggregates all projects. That root doesn't get plugin tasks (e.g. scripted from SbtPlugin). So if you ran scripted from the shell, you'd get "Not a valid command: scripted" / "No such setting/task" even though a subproject had the task.

What we changed

When using the aggregated key parser, a key is now valid if it exists in data for that scope or it's an aggregate key and every key it aggregates to exists in data. So (root, scripted) is accepted when the root aggregates a project that defines scripted, and running scripted at root runs it on that project as before.

Repro test

  • Scripted test: project/extra-projects-key-aggregate
    • Build: no explicit root; projects a and p; plugin adds extra project z → sbt creates auto root.
    • Only p defines the task check.
    • Test runs > check at root; without the fix this fails with "No such setting/task"; with the fix it runs p/check and passes.

AI disclosure

AI usage: I used AI tools (ChatGPT) to assist with this PR: implementation design, code changes, and test setup. The changes were verified locally (compile, lint, unit tests). I have reviewed and understand the code.


  • Reproduced the problem (scripted test captures the scenario).
  • Change compiles and passes lint (scalafmt, javafmt).
  • Unit tests pass (mainProj/test).
  • Scripted test added; run with scripted project/extra-projects-key-aggregate (after publishLocalBin or in CI).

…gation

When a plugin adds extraProjects, sbt creates an auto root that aggregates
all projects but has no plugin tasks (e.g. scripted). The aggregated key
parser filtered choices by data.contains(key), so (root, scripted) was
rejected and 'scripted' failed with 'No such setting/task'.

- Add optional structure param to scopedKeySelected and select
- Use isValidForAggregate when structure is present: accept key if it
  exists in data or aggregates to keys that all exist in data
- Pass structure from scopedKeyAggregated/scopedKeyAggregatedFilter
  so root-scoped keys that exist only on aggregated projects are valid
@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented Feb 4, 2026

@eed3si9n Ready for review!

- scopedKeySelected: structure is required; callers pass None or Some(structure)
- select: add two-arg overload for callers without structure; three-arg version
  has no default so aggregate path is explicit
@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented Feb 4, 2026

Please review again.

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 for the contribution. I can't tell from the diff it if fixes the bug or not. As per usual, please include repro test(s), like a scripted test, into the pull request, and declare AI usages if any - https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md.

…tion)

- project/extra-projects-key-aggregate: repro for sbt#4947
  Run 'check' at root; without fix: No such setting/task; with fix: runs p/check
@bitloi bitloi force-pushed the fix/4947-extra-projects-aggregate branch from 2500d40 to eb89e0e Compare February 4, 2026 21:13
@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented Feb 4, 2026

Thanks for the contribution. I can't tell from the diff it if fixes the bug or not. As per usual, please include repro test(s), like a scripted test, into the pull request, and declare AI usages if any - https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md.

Done, thanks for the review.

Key aggregation at root with extraProjects+auto-root aggregate was
requiring all aggregated projects to define a task (forall). Change to
exists so a task is valid if any aggregated project defines it.
@bitloi bitloi requested a review from eed3si9n February 4, 2026 22:08
The test for sbt#4947 needs an explicit root that aggregates all projects
including z from extraProjects. This validates that check works from
root when only defined in subproject p.
When extraProjects adds projects via plugins, the auto-root is created
before other projects (defined in build.sbt) are discovered. This caused
the auto-root to only aggregate the extraProjects, not all projects.

The fix updates processAutoAggregate to add missing projects to the
auto-root's aggregation after all projects have been discovered. The fix
only applies to auto-generated roots (when hasRoot=false), not to
user-defined root projects.

Fixes sbt#4947
@bitloi bitloi requested a review from eed3si9n February 5, 2026 01:21
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: extraProjects with auto-root aggregate breaks key aggregation [2.x] fix: extraProjects with auto-root aggregate breaks key aggregation Feb 5, 2026
@eed3si9n eed3si9n merged commit 2f27b5c into sbt:develop Feb 5, 2026
15 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.

extraProjects with auto-root aggregate breaks key aggregation

2 participants