问题描述
我有两个 Sbt 项目,my-commons 和 my-service.
I have two Sbt projects, my-commons and my-service.
依赖项
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"
)
我的服务:
依赖项
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.+"
)
我正在使用程序集 sbt 插件
I'm using the assembly sbt plugin
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
我在 sbt 程序集上遇到错误:
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?
推荐答案
在您的情况下,文件存在不同的内容,因此无法与 SBT 程序集插件合并.
In your case, files exist with different content and thus can't be merged with SBT assembly plugin.
两种可能的方法
使用程序集插件的合并过滤器来指定,要保留哪些文件,例如
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)
}
方法 2:
参见 http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies 关于如何排除传递依赖.
Approach 2:
See http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies on how to exclude transitive dependencies.
这篇关于如何排除 Sbt 中的传递依赖(在程序集插件的上下文中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!