How to exclude transitive dependency in Sbt ( in context of assembly plugin )?

Julias

I have two Sbt projects, my-commons and my-service.

my-commons

with the dependencies

libraryDependencies ++= Seq(
  "nz.ac.waikato.cms.weka" % "attributeSelectionSearchMethods" % "1.0.7",
  "de.bwaldvogel" % "liblinear" % "1.95"
  "io.dropwizard.metrics" % "metrics-graphite" % "3.1.2",
  "com.github.nscala-time" %% "nscala-time" % "2.2.0",
  "org.apache.hive" % "hive-jdbc" % "1.1.0-cdh5.4.5",
  "org.apache.hadoop" % "hadoop-common" % "2.6.0-cdh5.4.5",
  "org.apache.hadoop" % "hadoop-hdfs" % "2.6.0-cdh5.4.5"
)

my-service:

with the dependencies

libraryDependencies ++= {
  Seq(
    "ch.qos.logback" % "logback-classic" % "1.0.13",
    "io.spray" %% "spray-httpx" % "1.3.3",
    "io.spray" %% "spray-json" % "1.3.2",
    "io.spray" %% "spray-can" % "1.3.3",
    "io.spray" %% "spray-routing" % "1.3.3",
    "io.spray" %% "spray-testkit" % "1.3.3" % "test",
    "com.typesafe.akka" %% "akka-actor" % "2.3.9",
    "com.typesafe.akka" %% "akka-testkit" % "2.3.9" % "test",
    "org.specs2" %% "specs2-core" % "2.3.11" % "test",
    "org.json4s" %% "json4s-native" %  "3.2.11",
    "org.json4s" %% "json4s-ext" %  "3.2.11",
    "org.mockito" % "mockito-all" % "1.8.4" % "test",
    "com.mycommon.projects" % "my-commons" % "1.0.+"
  )

I'm using the assembly sbt plugin

   addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

I'm getting error on sbt assembly:

at java.lang.Thread.run(Thread.java:745)
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /home/me/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.7.jar:META-INF/maven/org.slf4j/slf4j-api/pom.properties
[error] /home/me/.ivy2/cache/com.twitter/parquet-hadoop-bundle/jars/parquet-hadoop-bundle-1.5.0-cdh5.4.5.jar:META-INF/maven/org.slf4j/slf4j-api/pom.properties

I've tried to exclude those libs from build but with no success.

libraryDependencies ~= { _ map {
  case m if m.organization.startsWith("org.apache") || m.organization.startsWith("com.twitter") || m.name.contains("parquet") =>
   m.exclude("org.slf4j","slf4j-api").
   exclude("org.slf4j","slf4j-log4j12")
   case m => m
 }}

Probably I'm doing something wrong... How can I resolve this dependency hell?

Martin Senne

In your case, files exist with different content and thus can't be merged with SBT assembly plugin.

Two approaches possible

Approach 1:

Use the merge filter of the assembly plugin to specify, which files to keep, e.g.

val sharedMergeStrategy: (String => MergeStrategy) => String => MergeStrategy =
  (old: (String) => MergeStrategy) => {
    case x if x.startsWith("META-INF/ECLIPSEF.RSA") => MergeStrategy.last
    case x if x.startsWith("META-INF/mailcap") => MergeStrategy.last
    case x if x.endsWith("plugin.properties") => MergeStrategy.last
    case x => old(x)
  }

Approach 2:

See http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies on how to exclude transitive dependencies.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Exclude transitive dependency of Gradle plugin

From Dev

Exclude transitive dependency of Gradle plugin

From Dev

How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

maven-shade-plugin : exclude a dependency and all its transitive dependencies

From Dev

Maven exclude transitive dependency of a transitive dependency

From Dev

Maven exclude transitive dependency of a transitive dependency

From Dev

exclude transitive shaded dependency in maven

From Dev

Why can't I seem to exclude this transitive dependency from build.sbt? (Continues to show up in ivyReport)

From Dev

Maven assembly plugin: how to include provided dependencies of transitive dependencies

From Dev

Maven assembly plugin: how to include provided dependencies of transitive dependencies

From Dev

How to exclude a direct dependency of a Maven Plugin

From Dev

SBT Scala Assembly Plugin

From Dev

SBT: How to exclude source files and documentation from the assembly?

From Dev

maven exclude plugin in dependency

From Java

How do I exclude all instances of a transitive dependency when using Gradle?

From Dev

maven assembly plugin dependencySet with transitive dependencies

From Dev

How to make dependency transitive in Gradle

From Dev

How to exclude LICENSE files in sbt-android-sdk plugin?

From Dev

exclude jars with SBT assemble plugin

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

DeDuplication error with SBT assembly plugin

From Dev

DeDuplication error with SBT assembly plugin

From Dev

How to exclude project dependency from classpath used by maven plugin

From Dev

Is there a simple way to specify a global dependency exclude in SBT

From Dev

Exclude test dependency resolution from `sbt compile`

From Dev

sbt - exclude certain dependency only during publish

From Dev

Grails: is it possible to exclude a plugin dependency of another plugin?

From Dev

Is this a transitive dependency?

Related Related

  1. 1

    Exclude transitive dependency of Gradle plugin

  2. 2

    Exclude transitive dependency of Gradle plugin

  3. 3

    How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

  4. 4

    How to use maven assembly plugin to exclude a package from dependency jar?

  5. 5

    maven-shade-plugin : exclude a dependency and all its transitive dependencies

  6. 6

    Maven exclude transitive dependency of a transitive dependency

  7. 7

    Maven exclude transitive dependency of a transitive dependency

  8. 8

    exclude transitive shaded dependency in maven

  9. 9

    Why can't I seem to exclude this transitive dependency from build.sbt? (Continues to show up in ivyReport)

  10. 10

    Maven assembly plugin: how to include provided dependencies of transitive dependencies

  11. 11

    Maven assembly plugin: how to include provided dependencies of transitive dependencies

  12. 12

    How to exclude a direct dependency of a Maven Plugin

  13. 13

    SBT Scala Assembly Plugin

  14. 14

    SBT: How to exclude source files and documentation from the assembly?

  15. 15

    maven exclude plugin in dependency

  16. 16

    How do I exclude all instances of a transitive dependency when using Gradle?

  17. 17

    maven assembly plugin dependencySet with transitive dependencies

  18. 18

    How to make dependency transitive in Gradle

  19. 19

    How to exclude LICENSE files in sbt-android-sdk plugin?

  20. 20

    exclude jars with SBT assemble plugin

  21. 21

    Maven assembly or shade plugin - How to exclude sources from jar?

  22. 22

    DeDuplication error with SBT assembly plugin

  23. 23

    DeDuplication error with SBT assembly plugin

  24. 24

    How to exclude project dependency from classpath used by maven plugin

  25. 25

    Is there a simple way to specify a global dependency exclude in SBT

  26. 26

    Exclude test dependency resolution from `sbt compile`

  27. 27

    sbt - exclude certain dependency only during publish

  28. 28

    Grails: is it possible to exclude a plugin dependency of another plugin?

  29. 29

    Is this a transitive dependency?

HotTag

Archive