我正在尝试使用sbt-assembly插件构建一个胖Jar。我在SBT版本0.13.1和汇编插件版本:0.11.2。
每当我在sbt控制台中运行汇编命令时,我遇到了这个错误:
更新:
[warn] Merging 'META-INF\LICENSE' with strategy 'rename'
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[debug] Merging 'META-INF\native\linux32\libleveldbjni.so' with strategy 'deduplicate'
[debug] Merging 'META-INF\native\linux64\libleveldbjni.so' with strategy 'deduplicate'
[debug] Merging 'META-INF\native\osx\libleveldbjni.jnilib' with strategy 'deduplicate'
[debug] Merging 'META-INF\native\windows32\leveldbjni.dll' with strategy 'deduplicate'
[debug] Merging 'META-INF\native\windows64\leveldbjni.dll' with strategy 'deduplicate'
[debug] Merging 'default.key' with strategy 'deduplicate'
java.lang.RuntimeException: deduplicate: different file contents found in the following:
mydef.key
mydef.key
at sbtassembly.Plugin$Assembly$.sbtassembly$Plugin$Assembly$$applyStrategy$1(Plugin.scala:253)
at sbtassembly.Plugin$Assembly$$anonfun$15.apply(Plugin.scala:270)
at sbtassembly.Plugin$Assembly$$anonfun$15.apply(Plugin.scala:267)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
at sbtassembly.Plugin$Assembly$.applyStrategies(Plugin.scala:272)
at sbtassembly.Plugin$Assembly$.x$4$lzycompute$1(Plugin.scala:172)
at sbtassembly.Plugin$Assembly$.x$4$1(Plugin.scala:170)
at sbtassembly.Plugin$Assembly$.stratMapping$lzycompute$1(Plugin.scala:170)
at sbtassembly.Plugin$Assembly$.stratMapping$1(Plugin.scala:170)
at sbtassembly.Plugin$Assembly$.inputs$lzycompute$1(Plugin.scala:214)
at sbtassembly.Plugin$Assembly$.inputs$1(Plugin.scala:204)
at sbtassembly.Plugin$Assembly$.apply(Plugin.scala:230)
at sbtassembly.Plugin$Assembly$$anonfun$assemblyTask$1.apply(Plugin.scala:373)
at sbtassembly.Plugin$Assembly$$anonfun$assemblyTask$1.apply(Plugin.scala:370)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[error] (cloud_ui/*:assembly) deduplicate: different file contents found in the following:
[error] mydef.key
[error] mydef.key
**[error](mymodule:*.assembly) deduplicate: different file contents found in the following:
[error] mydef.key
[error] mydef.key**
在检查我的build.sbt时,我发现IntelliJ抱怨“mergeStrategy in assembly”块。它的抱怨是:
预期的类型不匹配:Def Initialize [(String)=> Plugin.MergeStrategy],实际:DefInitialize [Any]
这是我的mergeStrategy:
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case PathList("org", "jboss", "netty", xs @ _*) => MergeStrategy.first
case PathList("META-INF", "jboss-beans.xml") => MergeStrategy.first
case PathList("org", "w3c", "dom", "TypeInfo.class") => MergeStrategy.first
case "jboss-beans.xml" => MergeStrategy.first
case "application.conf" => MergeStrategy.concat
case "unwanted.txt" => MergeStrategy.discard
case "rootdoc.txt" => MergeStrategy.discard
case x => old(x)
}
}
我已经在stackoverflow上查找了一些解决类似问题的资源,我想知道following resource是否有我问题的解决方案。
从知识的角度来看,我已经学会了足够的SBT用于构建目的,但到目前为止我还没有能够深入研究它的阴暗深度。但我准备好了。 如果有人可以指出我正确的方向,我可以去修正build.sbt文件中的错误以及我的'重复数据删除错误',这样我就可以实现构建我可以部署的胖罐的目标..
更新我自己尝试的内容,但未能使其正常工作 我修改了mergeStrategy以包含这一行:
case PathList(ps @ _*) if ps.last endsWith ".key" => MergeStrategy.first
修改后的mergeStrategy现在看起来像:
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case PathList(ps @ _*) if ps.last endsWith ".key" => MergeStrategy.first
case PathList("org", "jboss", "netty", xs @ _*) => MergeStrategy.first
case PathList("META-INF", "jboss-beans.xml") => MergeStrategy.first
case PathList("org", "w3c", "dom", "TypeInfo.class") => MergeStrategy.first
case "jboss-beans.xml" => MergeStrategy.first
case "application.conf" => MergeStrategy.concat
case "unwanted.txt" => MergeStrategy.discard
case "rootdoc.txt" => MergeStrategy.discard
case x =>
//val old = (mergeStrategy in assembly).value
old(x)
}
}
更新: 我解决了这个问题。我只是删除了额外的文件并重新重建。而且我没有必要对合并策略做任何其他事情。
答案 0 :(得分:3)
看起来你有2个名为mydef.key的文件 但是因为它们的内容不一样,并且sbt-assembly没有规则如何合并它,所以引发了异常。
检查两者的内容以及它们对您的构建是否重要。 如果不只是尝试添加:
case "mydef.key" => MergeStrategy.first