在我的sbt项目中,我愿意生成包含 src / test /...文件的测试jar,以便我可以将它们重新用于其他项目。
我尝试使用 sbt 命令生成此测试jar:
sbt test:assembly
在我的 build.sbt 中,我提供了以下 Test 范围配置:
import AssemblyKeys._
...
assemblySettings
Project.inConfig(Test)(assemblySettings)
jarName in (Test, assembly) := s"${name.value}-test-${version.value}.jar"
...
mergeStrategy in (Test, assembly) <<= (mergeStrategy in (Test, assembly)) { (old) =>
{
case "ECLIPSEF.RSA" => MergeStrategy.first
case x => old(x)
}
}
此配置失败,并显示以下错误:
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard' java.lang.RuntimeException: deduplicate: different file contents found in the following: ...\.ivy2\cache\org.eclipse.jetty.orbit\javax.transaction\orbits\javax.transaction-1.1.1.v201105210645.jar:META-INF/ECLIPSEF.RSA ...\.ivy2\cache\org.eclipse.jetty.orbit\javax.servlet\orbits\javax.servlet-3.0.0.v201112011016.jar:META-INF/ECLIPSEF.RSA ...\.ivy2\cache\org.eclipse.jetty.orbit\javax.mail.glassfish\orbits\javax.mail.glassfish-1.4.1.v201005082020.jar:META-INF/ECLIPSEF.RSA ...\.ivy2\cache\org.eclipse.jetty.orbit\javax.activation\orbits\javax.activation-1.1.0.v201105071233.jar:META-INF/ECLIPSEF.RSA 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) ... [error] (MyProject/test:assembly) deduplicate: different file contents found in the following: [error] ...\.ivy2\cache\org.eclipse.jetty.orbit\javax.transaction\orbits\javax.transaction-1.1.1.v201105210645.jar:META-INF/ECLIPSEF.RSA ...
对于测试范围(测试,装配)
,似乎忽略了mergeStrategy配置我的问题是 - 如何配置 build.sbt 为 test:assembly 生成的jar启用 mergeStrategy ?
答案 0 :(得分:1)
默认情况下,RSA文件问题将修复为0.12.0。
你写的合并策略很接近。它需要META-INF
作为模式的一部分。
mergeStrategy in (Test, assembly) <<= (mergeStrategy in (Test, assembly)) { (old) =>
{
case case PathList("META-INF", "ECLIPSEF.RSA") => MergeStrategy.first
case x => old(x)
}
}