[2.x] fix: Fix updateSbtClassifiers using wrong Scala version for cross-built plugins (#8495)

**Problem**

When cross-building sbt plugins with explicit `scalaVersion` set in `build.sbt`, the `updateSbtClassifiers` task fails because it uses the launcher's Scala version instead of the appropriate Scala version for the target sbt version.

For example, with this configuration:
```scala
lazy val root = (project in file("."))
  .enablePlugins(SbtPlugin)
  .settings(
    scalaVersion := "2.10.7",  // Explicit for IDE support
    crossSbtVersions := Seq("0.13.17", "1.0.0"),
  )
```

Running sbt "show updateSbtClassifiers" would fail with:
Error downloading org.scala-sbt:scripted-plugin_2.12:0.13.17

It should look for scripted-plugin_2.10:0.13.17 since sbt 0.13.x uses Scala 2.10.

**Solution**

Modified sbtClassifiersTasks in Defaults.scala to:
1. Check if the project is an sbt plugin (sbtPlugin.value)
2. For plugins, derive the Scala version from pluginCrossBuild / sbtBinaryVersion using PluginCross.scalaVersionFromSbtBinaryVersion
3. For non-plugins, continue using the launcher's Scala version (original behavior)
This commit is contained in:
calm 2026-01-12 13:19:24 -08:00 committed by GitHub
parent b4f73c9a7b
commit ebc11f04a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

View File

@ -3550,7 +3550,13 @@ object Classpaths {
classifiersModule := Def.uncached(classifiersModuleTask.value),
// Redefine scalaVersion and scalaBinaryVersion specifically for the dependency graph used for updateSbtClassifiers task.
// to fix https://github.com/sbt/sbt/issues/2686
scalaVersion := appConfiguration.value.provider.scalaProvider.version,
// For sbt plugins, use the Scala version corresponding to the sbt binary version being targeted.
// to fix https://github.com/sbt/sbt/issues/8026
scalaVersion := {
val isPlugin = sbtPlugin.value
if (isPlugin) (pluginCrossBuild / scalaVersion).value
else appConfiguration.value.provider.scalaProvider.version
},
scalaBinaryVersion := binaryScalaVersion(scalaVersion.value),
scalaEarlyVersion := CrossVersion.earlyScalaVersion(scalaVersion.value),
scalaOrganization := ScalaArtifacts.Organization,

View File

@ -0,0 +1,18 @@
// Test for https://github.com/sbt/sbt/issues/8026
// When building sbt plugins with explicit scalaVersion set,
// updateSbtClassifiers should use the correct Scala version for the sbt version.
lazy val root = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(
name := "test-sbt-cross-build",
// Explicitly set scala version - this is what caused the issue in #8026
// When scalaVersion is explicitly set, updateSbtClassifiers was using the
// launcher's Scala version instead of the plugin's Scala version.
// Before the fix, this would fail with:
// Error downloading org.scala-sbt:scripted-plugin_2.12:0.13.17
// because it used the launcher's Scala version (2.12) instead of the
// plugin's target Scala version derived from sbt binary version.
scalaVersion := "2.12.21",
)

View File

@ -0,0 +1 @@
ThisBuild / pluginCrossBuild / sbtVersion := "2.0.0"

View File

@ -0,0 +1 @@
> updateSbtClassifiers