我有两个Sbt项目, my-commons 和 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插件
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
我在sbt汇编时遇到错误:
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
我试图将这些lib排除在构建之外但没有成功。
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
}}
可能我做错了什么......我怎么能解决这种依赖呢?
答案 0 :(得分:3)
在您的情况下,文件存在不同的内容,因此无法与SBT程序集插件合并。
可能的两种方法
使用程序集插件的合并筛选器指定要保留的文件,例如
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)
}
有关如何排除传递依赖关系,请参阅http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies。
答案 1 :(得分:3)
当sbt-assembly合并包时,由于所选择的策略,有时存在冲突。由于这两个文件具有相同的名称但内容不同,因此sbt-assembly无法执行任何操作。这是默认策略:deduplicate
。
可能最好的解决方案是指定另一个merge strategy,在这种情况下,first
将是最佳选择。
在assembly.sbt
(在根目录中)(不是project/assembly.sbt
)中输入以下内容:
import AssemblyKeys._
assemblySettings
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case PathList("META-INF", "maven", "org.slf4j", "slf4j-api", "pom.properties") => MergeStrategy.first
case PathList("META-INF", "maven", "org.slf4j", "slf4j-api", "pom.xml") => MergeStrategy.first
case x => old(x)
}
}