mirror of https://github.com/sbt/sbt.git
[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:
parent
b4f73c9a7b
commit
ebc11f04a7
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
ThisBuild / pluginCrossBuild / sbtVersion := "2.0.0"
|
||||
|
|
@ -0,0 +1 @@
|
|||
> updateSbtClassifiers
|
||||
Loading…
Reference in New Issue