我正在尝试使用sbt-assembly将 scala 项目转换为可部署的 fat jar 。当我在 sbt 中运行我的组装任务时,我收到以下错误:
Merging 'org/apache/commons/logging/impl/SimpleLog.class' with strategy 'deduplicate'
:assembly: deduplicate: different file contents found in the following:
[error] /Users/home/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.1.1.jar:org/apache/commons/logging/impl/SimpleLog.class
[error] /Users/home/.ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.6.4.jar:org/apache/commons/logging/impl/SimpleLog.class
现在来自 sbt-assembly 文档:
如果多个文件共享相同的相对路径(例如,多个依赖 JAR 中名为 application.conf 的资源),默认策略是验证所有候选文件是否具有相同的内容,否则会出错。可以使用以下内置策略之一或编写自定义策略基于每个路径配置此行为:
MergeStrategy.deduplicate
是上面描述的默认值MergeStrategy.first
按类路径顺序选择第一个匹配的文件MergeStrategy.last
选择最后一个MergeStrategy.singleOrError
使用有关冲突的错误消息退出MergeStrategy.concat
简单地连接所有匹配的文件并包含结果MergeStrategy.filterDistinctLines
也连接,但沿途遗漏重复项MergeStrategy.rename
重命名源自 jar 文件的文件MergeStrategy.discard
简单地丢弃匹配的文件
通过这个我设置我的 build.sbt 如下:
import sbt._
import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
name := "my-project"
version := "0.1"
scalaVersion := "2.9.2"
crossScalaVersions := Seq("2.9.1","2.9.2")
//assemblySettings
seq(assemblySettings: _*)
resolvers ++= Seq(
"Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/",
"Sonatype Repository" at "http://oss.sonatype.org/content/repositories/releases/"
)
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "1.6.1" % "test",
"org.clapper" %% "grizzled-slf4j" % "0.6.10",
"org.scalaz" % "scalaz-core_2.9.2" % "7.0.0-M7",
"net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
)
scalacOptions += "-deprecation"
mainClass in assembly := Some("com.my.main.class")
test in assembly := {}
mergeStrategy in assembly := mergeStrategy.first
在 build.sbt 的最后一行,我有:
mergeStrategy in assembly := mergeStrategy.first
现在,当我运行 SBT 时,我收到以下错误:
error: value first is not a member of sbt.SettingKey[String => sbtassembly.Plugin.MergeStrategy]
mergeStrategy in assembly := mergeStrategy.first
有人可以指出我在这里可能做错了什么吗?
谢谢