Changing merge strategy with sbt-assembly plugin. retronym https://github.com/retronym/jzy3d-demo

2,768 views
Skip to first unread message

oscarvarto

unread,
Jul 29, 2012, 11:24:04 PM7/29/12
to simple-b...@googlegroups.com
Based on retronym's jzy3d-demo repo [1] I wrote a project/Build.scala: http://pastie.org/4355642

I want to get a fat jar with all the dependencies included, and I used sbt-assembly plugin.

However when I issue the command "sbt assembly" I get the following error message: http://pastie.org/4355615
For that reason, I tried to modify the merge strategy according to  [2].
One of the attempts is shown in lines 24-26 of project/Build.scala http://pastie.org/4355642
However I continue having the same error: http://pastie.org/4356577 I think the important part is this:

[info] Merging 'org/eclipse/swt/browser/IE$4.class' with strategy 'deduplicate'
java.lang.RuntimeException: deduplicate: different file contents found in the following:
/Users/oscarvarto/programacion/scala/jzy3d.demos/target/swt-debug.jar:org/eclipse/swt/browser/IE$4.class
/Users/oscarvarto/programacion/scala/jzy3d.demos/target/swt.jar:org/eclipse/swt/browser/IE$4.class

So I cannot change the merge strategy (it continues to be 'deduplicate' when I was expecting it to be 'concat')

How can I get the fat jar with sbt-assembly?

Thanks.

[1] https://github.com/retronym/jzy3d-demo
[2] https://github.com/sbt/sbt-assembly#merge-strategy

eugene yokota

unread,
Jul 30, 2012, 12:42:44 PM7/30/12
to simple-b...@googlegroups.com
Hi Oscar,

The sbt-assembly's readme describes settings you can add to customize
the plugin.
If you see the [Applying the Plugin to a Project (Adding the assembly Task)][3],
it says

> full configuration:
>
> import sbtassembly.Plugin._
> import AssemblyKeys._
>
> lazy val sub = Project("sub", file("sub"),
> settings = buildSettings ++ assemblySettings ++
> Seq( // your settings here
> ))

Note the comment "// your settings here."
The exact way the settings are loaded doesn't matter, but it needs to
be passed into the project in one way or the other. Your mergeStrategy
isn't. Try something like:

lazy val root = Project(
"jz3dSamples",
file("."),
settings = commonSettings ++ Seq(
libraryDependencies ++= Seq(
"org.jzy3d" % "jzy3d" % "0.9" from
"http://www.jzy3d.org/release/0.9a3/org.jzy3d-0.9.jar"
),
mergeStrategy in assembly := {
case _ => MergeStrategy.concat
}
) ++
addZipJar("org.jzy3d" % "jzy3d-deps" % "0.9" from
"http://www.jzy3d.org/release/0.9a3/org.jzy3d-0.9-dependencies.zip",
Compile) ++
addZipJar("org.jzy3d" % "jzy3d-native" % "0.9" from
"http://www.jzy3d.org/release/0.9a3/org.jzy3d-0.9-binaries-%s.zip".format(arch),
Compile)
)

Also, if multiple jars are bringing in class files, the strategy I'd
use would be MergeStrategy.first, not concat, and would only override
the said package:

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case x if x startsWith "org/eclipse/swt/browser/" => MergeStrategy.first
case x => old(x)
}
}

-eugene

[3]: https://github.com/sbt/sbt-assembly#applying-the-plugin-to-a-project-adding-the-assembly-task
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/o0MvF2T9uykJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-build-tool?hl=en.

oscarvarto

unread,
Jul 31, 2012, 2:52:38 PM7/31/12
to simple-b...@googlegroups.com
Thank you very much Eugene!

Please, check the acknowledgments at https://github.com/oscarvarto/benchmarkPlots#acknowledgements
Reply all
Reply to author
Forward
0 new messages