Skip to content

[2.x] updateSbtClassifiers task fails with error "Error downloading default:<projectName>-build_sbt2.0.0-M3_3:0.1.0-SNAPSHOT" #8022

@unkarjedy

Description

@unkarjedy

steps

  1. Create a new sbt 2.0.0-M3 project with name testProject.
    Rename the directory to testProjectDirName (this will be important later just for debugging purposes)
sbt new scala/scala3.g8 --name=testProject
mv testProject testProject_DirName
cd testProject_DirName
echo "sbt.version=2.0.0-M3" > project/build.properties
  1. Run sbt "show updateSbtClassifiers ; last updateSbtClassifiers"
    (using "last" to show the error details right away)

problem

sbt tries to download an artifact named "testprojectdirname-build_sbt2.0.0-M3_3" from all known repositories.
The artifact is not published, and it obviously fails with error Error downloading default:testproject-build_sbt2.0.0-M3_3:0.1.0-SNAPSHOT.
Full error output:

[error] (updateSbtClassifiers) sbt.librarymanagement.ResolveException: Error downloading default:testprojectdirname-build_sbt2.0.0-M3_3:0.1.0-SNAPSHOT
[error]   Not found
[error]   not found: /Users/dmitrii.naumenko/.ivy2/local/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/testprojectdirname-build_sbt2.0.0-M3_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/maven-releases/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/testprojectdirname-build_sbt2.0.0-M3_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://repo.scala-sbt.org/scalasbt/maven-snapshots/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/testprojectdirname-build_sbt2.0.0-M3_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/default/testprojectdirname-build_sbt2.0.0-M3_3/0.1.0-SNAPSHOT/ivys/ivy.xml

expectation

updateSbtClassifiers task shouldn't fail

notes

I noticed the issue when porting sbt-structure to sbt 2.0 (cross-compile).
updateSbtClassifiers is used to extract the structure of the meta-build.

implementation notes

I debugged sbt.Classpaths.sbtClassifiersTasks which led to sbt.Classpaths.classifiersModuleTask.
I noticed that when GetClassifiersModule is constructed, its dependencies contain some strange ModuleID (the second one)

org.scala-sbt:sbt:2.0.0-M3
default:testprojects_dirname-build:0.1.0-SNAPSHOT

Notice that the artifact name represents the directory name and none of the projects.
This gets to sbt.librarymanagement.DependencyResolution#update which tries to resolve it from the remote repositories and obviously fails.

The second dependency comes from pluginIDs which is constructed based on the meta-build full classpath.

This issue is similar to #798
The fix was

val pluginJars = pluginClasspath.filter(_.data.isFile) // exclude directories: an approximation to whether they've been published

However in sbt 2.0 the sbt.PluginData#definitionClasspath points to a jar file, not to the directory with classes.

You can see that inspecting this part (I used a custom task to debug it)

val ref = thisProjectRef.value
val unit = loadedBuild.value.units(ref.build).unit
val converter = unit.converter
val pluginClasspath = unit.plugins.fullClasspath.toVector

The output will be like this:

Attributed(${OUT}/jvm/scala-3.6.2/testproject_dirname-build/testproject_dirname-build_sbt2.0.0-M3_3-0.1.0-SNAPSHOT.jar>sha256-a281266bb85297dff9648506156b379b01d51a25e9a5e47dffe372fd7b31bc83/1045)
Attributed(${SBT_BOOT}/scala-3.6.2/lib/scala-library.jar)
Attributed(${SBT_BOOT}/scala-3.6.2/lib/scala3-compiler_3-3.6.2.jar)
...

It seems like we should use unit.plugins.pluginData.dependencyClasspath instead of unit.plugins.fullClasspath (we shouldn't include sbt.PluginData#definitionClasspath).
It fixes the issue locally.
I will prepare the PR with the fix soon

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions