From 79c60ca4c10d85a6fd18f8e5d35dc39141d07adf Mon Sep 17 00:00:00 2001 From: Pegasus <42954461+leonace924@users.noreply.github.com> Date: Thu, 15 Jan 2026 22:52:38 -0500 Subject: [PATCH] [2.x] fix: Allow dependencyTree to run despite eviction errors (#8554) **Problem** When binary compatibility eviction errors occur, users cannot run `dependencyTree` to debug the dependency conflict because it fails with the same eviction error. **Solution** Set `evictionErrorLevel` and `assumedEvictionErrorLevel` to `Level.Warn` for the `dependencyTreeIgnoreMissingUpdate` task, allowing the dependency tree to be displayed even when eviction errors are present. Fixes #7255 --- .../sbt/plugins/DependencyTreeSettings.scala | 6 ++++-- .../dependency-graph/eviction-error/build.sbt | 19 +++++++++++++++++++ .../dependency-graph/eviction-error/test | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 sbt-app/src/sbt-test/dependency-graph/eviction-error/build.sbt create mode 100644 sbt-app/src/sbt-test/dependency-graph/eviction-error/test diff --git a/main/src/main/scala/sbt/plugins/DependencyTreeSettings.scala b/main/src/main/scala/sbt/plugins/DependencyTreeSettings.scala index ed47af3af..4661f5fdb 100644 --- a/main/src/main/scala/sbt/plugins/DependencyTreeSettings.scala +++ b/main/src/main/scala/sbt/plugins/DependencyTreeSettings.scala @@ -24,7 +24,7 @@ import sbt.internal.util.complete.DefaultParsers.* import sbt.io.IO import sbt.io.syntax.* import sbt.librarymanagement.* -import sbt.util.Logger +import sbt.util.{ Level, Logger } import scala.Console private[sbt] object DependencyTreeSettings: @@ -123,9 +123,11 @@ OPTIONS val is = new IvySbt((dependencyTreeIgnoreMissingUpdate / ivyConfiguration).value) new is.Module(moduleSettings.value) }, - // don't fail on missing dependencies + // don't fail on missing dependencies or eviction errors dependencyTreeIgnoreMissingUpdate / updateConfiguration := updateConfiguration.value .withMissingOk(true), + dependencyTreeIgnoreMissingUpdate / evictionErrorLevel := Level.Warn, + dependencyTreeIgnoreMissingUpdate / assumedEvictionErrorLevel := Level.Warn, dependencyTreeIgnoreMissingUpdate := Def.uncached { // inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in ignoreMissingUpdate` Project.inTask(dependencyTreeIgnoreMissingUpdate, Classpaths.updateTask).value diff --git a/sbt-app/src/sbt-test/dependency-graph/eviction-error/build.sbt b/sbt-app/src/sbt-test/dependency-graph/eviction-error/build.sbt new file mode 100644 index 000000000..e5f40f777 --- /dev/null +++ b/sbt-app/src/sbt-test/dependency-graph/eviction-error/build.sbt @@ -0,0 +1,19 @@ +// Test that dependencyTree works despite eviction errors +// This demonstrates the fix for https://github.com/sbt/sbt/issues/7255 + +ThisBuild / scalaVersion := "2.13.12" +ThisBuild / csrCacheDirectory := (ThisBuild / baseDirectory).value / "coursier-cache" + +// Create a binary incompatible eviction using real Maven dependencies: +// - scalacheck 1.14.3 depends on test-interface 1.0 +// - scalacheck 1.15.4 depends on test-interface 1.0 +// - We force an eviction by depending on incompatible versions +// Or simpler: use libraries with known eviction issues + +// cats-effect 2.x and 3.x are binary incompatible (early-semver) +// fs2 2.5.x depends on cats-effect 2.x +// We also add cats-effect 3.x directly to force eviction +libraryDependencies ++= Seq( + "co.fs2" %% "fs2-core" % "2.5.11", // depends on cats-effect 2.x + "org.typelevel" %% "cats-effect" % "3.3.0" // cats-effect 3.x (incompatible) +) diff --git a/sbt-app/src/sbt-test/dependency-graph/eviction-error/test b/sbt-app/src/sbt-test/dependency-graph/eviction-error/test new file mode 100644 index 000000000..00910adff --- /dev/null +++ b/sbt-app/src/sbt-test/dependency-graph/eviction-error/test @@ -0,0 +1,2 @@ +# Test that dependencyTree works despite eviction errors (issue #7255) +> dependencyTree