2
votes

In my sbt project I am willing to generate test jar containing src/test/... files so that I can re-use them for other projects.

I attempt to generate this test jar with this sbt command:

sbt test:assembly

In my build.sbt I provide following Test scope config:

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)
 }
}

This configuration fails with following error:

[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
...

It seems that the mergeStrategy configuration is ignored for Test scope (Test, assembly)

My question is - how to configure build.sbt to enable mergeStrategy for jar generated by test:assembly?

1
I've had same problem.It was solved by stackoverflow.com/questions/25144484/…Alexander
@Alexander: I am sorry but I fail to see how your example is different to what I already do. My issue is not related to generally being unable to merge during assembly! My issue is being unable to merge solely during TEST assemblyReinis

1 Answers

1
votes

RSA file issue will be fixed in 0.12.0 by default.

The merge strategy you wrote were close. It needs META-INF as part of the pattern.

mergeStrategy in (Test, assembly) <<= (mergeStrategy in (Test, assembly)) { (old) =>
  {
    case case PathList("META-INF", "ECLIPSEF.RSA") => MergeStrategy.first
    case x => old(x)
  }
}