sbt dependencyTree
unexpectedly includes projects that are depended on with scope Test
, which should not happen.
Starting with a barebones project like this:
name := "root"
ThisBuild / scalaVersion := "2.13.15"
lazy val common = project
lazy val a = project.dependsOn(common)
lazy val b = project.dependsOn(common % Test)
(The contents of the projects are irrelevant for this example.)
Running dependencyTree
for project a
correctly shows that it has a compile dependency on common
:
❯ sbt a/dependencyTree
[info] welcome to sbt 1.10.6 (Eclipse Adoptium Java 23.0.1)
…
[info] a:a_2.13:0.1.0-SNAPSHOT [S]
[info] +-common:common_2.13:0.1.0-SNAPSHOT [S]
Running the same for project b
unexpectedly still outputs common
, although not as part of the dependency tree of b
tree:
❯ sbt b/dependencyTree
[info] welcome to sbt 1.10.6 (Eclipse Adoptium Java 23.0.1)
…
[info] b:b_2.13:0.1.0-SNAPSHOT [S]
[info] common:common_2.13:0.1.0-SNAPSHOT
This has practical negative consequences: while sbt does avoid compiling common
during the compile task for b
, other plugins like sbt-native-packager will still compile and prepare common
when packaging b
, which wastes a lot of time and size to the final package:
❯ sbt b/compile
…
[info] compiling 1 Scala source to …/b/target/scala-2.13/classes ...
[success] Total time: 2 s, completed 14 Dec 2024, 12:48:16
❯ sbt b/stage
…
[info] Wrote …/b/target/scala-2.13/b_2.13-0.1.0-SNAPSHOT.pom
[info] Main Scala API documentation to …/b/target/scala-2.13/api...
[info] Main Scala API documentation successful.
[info] Wrote …/common/target/scala-2.13/common_2.13-0.1.0-SNAPSHOT.pom
[info] Main Scala API documentation to …/common/target/scala-2.13/api...
[info] compiling 1 Scala source to …/common/target/scala-2.13/classes ...
[info] Main Scala API documentation successful.
[success] Total time: 2 s, completed 14 Dec 2024, 12:48:24
This seems like such an obvious problem that I wonder if I’m missing anything. Or have I stumbled into a bug?
waterfallweb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.