使用sbt-assembly的汇编合并策略问题 [英] assembly-merge-strategy issues using sbt-assembly
问题描述
我正在尝试使用 sbt-assembly 将scala项目转换为可部署的胖罐。当我在sbt中运行我的程序集任务时,我收到以下错误:
合并org / apache / commons / logging / impl /simpleLog.class'与策略'重复数据删除'
:装配:重复数据删除:在以下内容中找到不同的文件内容:
[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
在classpath顺序中选择匹配文件中的第一个
MergeStrategy.last
选择最后一个
MergeStrategy.singleOrError
bails out with a error message on conflict
MergeStrategy.concat
简单地连接所有匹配的文件,并且包含结果
MergeStrategy.filterDistinctLines
也连接起来,但是一起删除重复
MergeStrategy.rename
重命名源自jar文件的文件
MergeStrategy.discard
只需丢弃匹配的文件
我设置我的build.sbt如下:
import sbt._
/ pre>
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:_ *)
解析器+在http://repo.typesafe.com/typesafe/releases/上的$ = Seq(
Typesafe Releases Repository),btype $ Snapshots Repository,http://repo.typesafe。 com / typesafe / snapshots /,
Sonatype Repositoryathttp://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在汇编y:= Some(com.my.main.class)
test in assembly:= {}
mergeStrategy in assembly:= mergeStrategy.first
在build.sbt的最后一行,我有:
mergeStrategy in assembly:= mergeStrategy.first
现在,当我运行SBT,我得到以下错误:
错误:值首先不是sbt.SettingKey的成员[String => sbtassembly.Plugin.MergeStrategy]
mergeStrategy在程序集中:= mergeStrategy.first
有人可以指出在这里我可能做错了什么?
谢谢
解决方案我认为它应该是
MergeStrategy.first
,其资本M
,所以mergeStrategy in assembly: = MergeStrategy.first
。I am trying to convert a scala project into a deployable fat jar using sbt-assembly. When I run my assembly task in sbt I am getting the following error:
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
Now from the sbt-assembly documentation:
If multiple files share the same relative path (e.g. a resource named application.conf in multiple dependency JARs), the default strategy is to verify that all candidates have the same contents and error out otherwise. This behavior can be configured on a per-path basis using either one of the following built-in strategies or writing a custom one:
MergeStrategy.deduplicate
is the default described aboveMergeStrategy.first
picks the first of the matching files in classpath orderMergeStrategy.last
picks the last oneMergeStrategy.singleOrError
bails out with an error message on conflictMergeStrategy.concat
simply concatenates all matching files and includes the resultMergeStrategy.filterDistinctLines
also concatenates, but leaves out duplicates along the wayMergeStrategy.rename
renames the files originating from jar filesMergeStrategy.discard
simply discards matching filesGoing by this I setup my build.sbt as follows:
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
In the last line of the build.sbt, I have:
mergeStrategy in assembly := mergeStrategy.first
Now, when I run SBT, I get the following error:
error: value first is not a member of sbt.SettingKey[String => sbtassembly.Plugin.MergeStrategy] mergeStrategy in assembly := mergeStrategy.first
Can somebody point out what I might be doing wrong here?
Thanks
解决方案I think it should be
MergeStrategy.first
with a capitalM
, somergeStrategy in assembly := MergeStrategy.first
.这篇关于使用sbt-assembly的汇编合并策略问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!