Skip to content

[2.x] fix: Fixes subproject deps with different Scala versions#8681

Merged
eed3si9n merged 10 commits intosbt:developfrom
bitloi:fix/4847-inter-project-variant-scala
Feb 3, 2026
Merged

[2.x] fix: Fixes subproject deps with different Scala versions#8681
eed3si9n merged 10 commits intosbt:developfrom
bitloi:fix/4847-inter-project-variant-scala

Conversation

@bitloi
Copy link
Copy Markdown
Contributor

@bitloi bitloi commented Feb 2, 2026

Fix inter-project dependencies with different Scala versions

When a project depended on another project that was built with a different Scala binary version (e.g. 2.12 vs 2.13), compilation could fail with "not found: value X" because resolution was asking for the wrong artifact.

This change updates how we build the ModuleID for inter-project dependencies in projectDependenciesTask: we now request the dependency’s Scala binary version (e.g. bar_2.12) instead of the current project’s, so the resolver can find the right artifact. We keep existing behavior for Disabled and Constant cross-version, and add a small safeguard in the default case when the dependency’s Scala version differs from the current project’s.

  • Scripted test: dependency-management/i4847-inter-project-variant-scala — bar (2.12) and baz (2.13), baz depends on bar; verifies baz/run succeeds.
  • Note: dependency-management/provided-multi passes locally (Java 17); if it fails in CI (e.g. on Java 25), that appears to be a pre-existing or environment-specific issue, not caused by this fix.

Closes #4847

When project baz (e.g. scala 2.13) dependsOn bar (e.g. scala 2.12),
resolution was requesting bar_2.13 (dependent's sbv) instead of bar_2.12
(dependency's sbv), so inter-project resolver could not find the artifact.

In projectDependenciesTask, for cross-versioned inter-project deps
(Binary, Full, For3Use2_13, For2_13Use3), use the dependency project's
scala version (depSBV / dep full version) to build a constant cross
version so resolution looks up the actual bar_2.12 artifact.

- Use sbt.librarymanagement.For3Use2_13/For2_13Use3 in pattern match
- Add scripted test dependency-management/i4847-inter-project-variant-scala
  (bar 2.12, baz 2.13, baz dependsOn bar % Runtime; baz/update and baz/run)
Generated-by: Gen-AI
- Remove % Runtime from dependsOn to allow compile-time access to bar
- Fix output path to baz/output to match test expectation
Add 'if sbv != depSBV' guard to Binary, Full, For3Use2_13, and For2_13Use3
cases in projectDependenciesTask. When projects share the same Scala version,
preserve original behavior to avoid breaking inter-project resolution.

Fixes dependency-management/provided-multi test failure.
Add 'if sbv != depSBV' guard to Binary, Full, For3Use2_13, and For2_13Use3
cases in projectDependenciesTask. When projects share the same Scala version,
preserve original behavior exactly to avoid breaking class loader caching.

Fixes dependency-management/provided-multi and project/scala-loader tests.
@bitloi bitloi force-pushed the fix/4847-inter-project-variant-scala branch from f7dfb3b to 3052b6a Compare February 3, 2026 05:49
@bitloi bitloi requested a review from eed3si9n February 3, 2026 06:19
@bitloi bitloi requested review from eed3si9n February 3, 2026 12:40
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/inter-project dependencies with different Scala versions [2.x] fix: Fixes subproject deps with different Scala versions Feb 3, 2026
@eed3si9n eed3si9n merged commit b0601b4 into sbt:develop Feb 3, 2026
15 checks passed
dev-miro26 added a commit to dev-miro26/sbt that referenced this pull request Feb 24, 2026
Per review feedback, move the Scala version mismatch check from
compileTask to projectDependenciesTask, where PR sbt#8681 already handles
Scala version mixing logic. This provides earlier detection and keeps
the validation co-located with cross-version resolution.

Generated-by: Copilot
eed3si9n pushed a commit that referenced this pull request Feb 25, 2026
sbt 2.x allows `dependsOn(...)` between subprojects with mismatched
Scala versions without any warning or error. This can lead to confusing
classpath issues at compile or runtime, especially now that Scala 3.8+
has dropped backward TASTy compatibility with 2.13.

Per review feedback, move the Scala version mismatch check from
compileTask to projectDependenciesTask, where PR #8681 already handles
Scala version mixing logic. This provides earlier detection and keeps
the validation co-located with cross-version resolution.

Generated-by: Copilot
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
sbt 2.x allows `dependsOn(...)` between subprojects with mismatched
Scala versions without any warning or error. This can lead to confusing
classpath issues at compile or runtime, especially now that Scala 3.8+
has dropped backward TASTy compatibility with 2.13.

Per review feedback, move the Scala version mismatch check from
compileTask to projectDependenciesTask, where PR sbt#8681 already handles
Scala version mixing logic. This provides earlier detection and keeps
the validation co-located with cross-version resolution.

Generated-by: Copilot
eed3si9n added a commit that referenced this pull request Mar 1, 2026
sbt 2.x allows `dependsOn(...)` between subprojects with mismatched
Scala versions without any warning or error. This can lead to confusing
classpath issues at compile or runtime, especially now that Scala 3.8+
has dropped backward TASTy compatibility with 2.13.

Per review feedback, move the Scala version mismatch check from
compileTask to projectDependenciesTask, where PR #8681 already handles
Scala version mixing logic. This provides earlier detection and keeps
the validation co-located with cross-version resolution.

Generated-by: Copilot

Co-authored-by: dev-miro26 <[email protected]>
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.

Inter-project dependencies break on variant Scala binary versions

2 participants