Search code examples
sbtsbt-assemblysbt-plugin

Override a version of transitive dependency in sbt


I have a requirement to override a transitive dependency to a later version of the same.

In maven I can do this by simply adding the overriding one on top.

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.8.9</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.8.9</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-scala_2.11</artifactId>
      <version>2.8.9</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_${scala.version.dist}</artifactId>
      <version>${spark.version}</version>
    </dependency>
    <dependency>
    <dependency>
      <groupId>com.mypackage.road</groupId>
      <artifactId>package-that-contains-transitive-deps</artifactId>
      <version>4.2.0</version>
    </dependency>

How can i do this in sbt? Also like the GUI that is available in maven (Dependency-Hierarchy tab) which shows which jars are overriding the others, how can i see that in sbt?

I have already tried to force the versions I want using dependencyOverrides. But the issue is still there.So how can I check that the older version is exactly evicted by the version I am overriding. sbt dependencyTree is not showing that the newer one has evicted the transitive dependency.


Solution

  • You can override versions using dependencyOverrides setting (see linked answer).

    Then you normally see evicted versions during update. But if for some reason you don't, you can run show evicted in sbt to output eviction warnings. Example output:

    ...
    [warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
    [warn]  * org.scalameta:inputs_2.12:2.1.2 is selected over 2.0.0-M3
    [warn]      +- org.scalameta:scalameta_2.12:2.1.2                 (depends on 2.1.2)
    [warn]      +- org.scalameta:quasiquotes_2.12:2.1.2               (depends on 2.1.2)
    ...
    [warn] Run 'evicted' to see detailed eviction warnings
    [info] Here are other depedency conflicts that were resolved:
    [info]  * com.trueaccord.scalapb:scalapb-runtime_2.12:0.6.6 is selected over 0.6.2
    [info]      +- org.scalameta:langmeta_2.12:2.1.2                  (depends on 0.6.2)
    [info]      +- org.scalameta:metals_2.12:0.1-SNAPSHOT             (depends on 0.6.2)
    [info]  * com.lihaoyi:sourcecode_2.12:0.1.4 is selected over 0.1.3
    [info]      +- com.lihaoyi:fansi_2.12:0.2.5                       (depends on 0.1.4)
    [info]      +- com.lihaoyi:fastparse-utils_2.12:0.4.4             
    ...