Skip to content

Conversation

eed3si9n
Copy link
Member

@eed3si9n eed3si9n commented Aug 10, 2025

Fixes #7770

Problem

While sbt-dependency-graph is useful, not just for the basic ASCII graph, but for DOT file generation etc, it adds a large number of settings and tasks for combination of formats and actions to the point that we actually disable most of them by default.

Solution

I've had an idea for a while that dependencyTree can be implemented as a inputTask that accepts its own subcommands and options, and this implements that.

For example, to open the browser that hosts a DOT file, now you can write
dependencyTree dot --browse

Output

sbt:foo> dependencyTree
default:foo_2.13:0.1.0-SNAPSHOT [S]
  +-org.typelevel:cats-effect_2.13:3.1.0 [S]
    +-org.typelevel:cats-effect-kernel_2.13:3.1.0 [S]
    | +-org.typelevel:cats-core_2.13:2.6.0 [S]
    |   +-org.typelevel:cats-kernel_2.13:2.6.0 [S]
    |   +-org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4 [S]
    |
    +-org.typelevel:cats-effect-std_2.13:3.1.0 [S]
      +-org.typelevel:cats-effect-kernel_2.13:3.1.0 [S]
        +-org.typelevel:cats-core_2.13:2.6.0 [S]
          +-org.typelevel:cats-kernel_2.13:2.6.0 [S]
          +-org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4 [S]

[success] elapsed time: 0 s, cache 100%, 3 disk cache hits
sbt:foo> dependencyTree help
[info] dependencyTree task displays the dependency graph.
[info]
[info] USAGE
[info]   dependencyTree [subcommand] [options]
[info]
[info] SUBCOMMAND
[info]   tree         Prints ascii tree (default)
[info]   list         Prints list of all dependencies
[info]   graph        Prints GraphViz DOT file
[info]   dot          Same as graph
[info]   html         Creates HTML page
[info]   html-graph   Creates HTML page with GraphViz DOT file
[info]   json         Prints JSON
[info]   xml          Prints GraphML
[info]   stats        Prints statistics for all dependencies
[info]
[info]   help         Prints this help
[info]
[info] OPTIONS
[info]   --quiet      Returns the output as task value, replacing asString
[info]   --out <file> Writes the output to the specified file;
[info]                The file extension will influence the default subcommand
[info]   --browse     Opens the browser when combined with graph or html subcommand
[success] elapsed time: 0 s
// $ sbt dependencyTree json | grep 'text'
[{"text":"default:foo_2.13:0.1.0-SNAPSHOT","children":[{"text":"org.typelevel:cats-effect_2.13:3.1.0","children":[{"text":"org.typelevel:cats-effect-kernel_2.13:3.1.0","children":[{"text":"org.typelevel:cats-core_2.13:2.6.0","children":[{"text":"org.typelevel:cats-kernel_2.13:2.6.0","children":[]},{"text":"org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4","children":[]}]}]},{"text":"org.typelevel:cats-effect-std_2.13:3.1.0","children":[{"text":"org.typelevel:cats-effect-kernel_2.13:3.1.0","children":[{"text":"org.typelevel:cats-core_2.13:2.6.0","children":[{"text":"org.typelevel:cats-kernel_2.13:2.6.0","children":[]},{"text":"org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4","children":[]}]}]}]}]}]}]

@eed3si9n eed3si9n force-pushed the wip/dependency-tree branch from 99c5cb7 to 1978692 Compare August 10, 2025 04:34
**Problem**
While sbt-dependency-graph is useful, not just for the basic ASCII graph,
but for DOT file generation etc, it adds a large number of settings and
tasks for combination of formats and actions to the point that
we actually disable most of them by default.

**Solution*
I've had an idea for a while that dependencyTree can be implemented
as a inputTask that accepts its own subcommands and options,
and this implements that.

For example, to open the browser that hosts a DOT file, now you can write
    dependencyTree dot --browse
@eed3si9n eed3si9n force-pushed the wip/dependency-tree branch from 1978692 to 61fe604 Compare August 10, 2025 04:37
@eed3si9n eed3si9n merged commit d7d2a6f into sbt:develop Aug 10, 2025
22 of 23 checks passed
@eed3si9n eed3si9n deleted the wip/dependency-tree branch August 10, 2025 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dependencyTree should also display/write json, not just text
1 participant