Sbt Check Dependency Relationship

Abstract: This article introduce a plugin to help check the relationship of the dependencies in Sbt.

We usually use the Maven Helper in IntelliJ to resolve the conflict of the dependencies of Maven. So how about the sbt?

There is an Sbt plugin can be used for that target: sbt-dependency-graph.

The basic usage is as follow:

  1. sbt backend/dependencyTree: show ASCII graph in a terminal. The output will look like as follows: if the dependency is not active, it will be noted as (evicted by: 1.3.4). For example, you dependent A[v1] and B[v2], and A[v1] dependent on the B[v1], then the B[v1] will be evicted by the B[v2].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[info]   +-com.typesafe.akka:akka-http-xml_2.13:10.1.8 [S]
[info] | +-com.typesafe.akka:akka-http_2.13:10.1.8 [S]
[info] | | +-com.typesafe.akka:akka-http-core_2.13:10.1.8 [S]
[info] | | +-com.typesafe.akka:akka-parsing_2.13:10.1.8 [S]
[info] | |
[info] | +-org.scala-lang.modules:scala-xml_2.13:1.2.0 [S]
[info] |
[info] +-com.typesafe.akka:akka-http_2.13:10.1.8 [S]
[info] | +-com.typesafe.akka:akka-http-core_2.13:10.1.8 [S]
[info] | +-com.typesafe.akka:akka-parsing_2.13:10.1.8 [S]
[info] |
[info] +-com.typesafe.akka:akka-stream_2.13:2.5.23 [S]
[info] | +-com.typesafe.akka:akka-actor_2.13:2.5.23 [S]
[info] | | +-com.typesafe:config:1.3.3 (evicted by: 1.3.4)
[info] | | +-com.typesafe:config:1.3.4
[info] | | +-org.scala-lang.modules:scala-java8-compat_2.13:0.9.0 [S]
[info] | |
[info] | +-com.typesafe.akka:akka-protobuf_2.13:2.5.23 [S]
  1. sbt backend/dependencyBrowseGraph: show graph in a browser. you can check the dependency eviction relation. According to the graph, we can find the rectangle with dash line is the dependency which is evicted by others. By the way, the generated files will be in the target folder: graph.html, dependencies.dot.js and dependencies.dot.

sbt dependency graph broswer image

I think this plugin is essential for the complex sbt project.