Reputation: 113
I am using sbt-assembly to package my scala object, but I can't figure out how to assemble a fat jar for a project that aggregates and depends on many other projects.
For example, I have:
lazy val a = project in file("project-a")
lazy val poj = (project in file("project-poj")).dependsOn(a)
lazy val root = (project in file(".")).aggregate(a, poj)
After sbt assembly, poj-assembly.jar and root-assembly.jar did not include scala classes in project a.
Thanks for help.
Upvotes: 1
Views: 1056
Reputation: 95604
poj-assembly.jar
should include the classes from project a. Please provide a fully working example on Github if you observe otherwise, because that would be sbt-assembly bug.
Here's my demonstration.
$ sbt
> poj/assembly
[info] Compiling 1 Scala source to /xxx/project-poj/target/scala-2.12/classes...
[info] Including: scala-library-2.12.1.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Strategy 'discard' was applied to a file
[info] SHA-1: 58a67743530fef8d0713759060c685c536d29591
[info] Packaging /xxx/project-poj/target/scala-2.12/poj-assembly-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 2 s, completed Jan 22, 2017 8:05:29 AM
> exit
$ java -jar project-poj/target/scala-2.12/poj-assembly-0.1.0-SNAPSHOT.jar
A(1)
As you see above, it says A(1)
, which is a class I defined in project a. The following is the files in the build.
sbt.version=0.13.13
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
lazy val root = (project in file("."))
.aggregate(a, poj)
.settings(
organization in ThisBuild := "com.example",
scalaVersion in ThisBuild := "2.12.1",
version in ThisBuild := "0.1.0-SNAPSHOT",
name := "Hello"
)
lazy val a = (project in file("project-a"))
lazy val poj = (project in file("project-poj"))
.dependsOn(a)
package example
case class A(a: Int)
package example
object Hello extends App {
println(example.A(1))
}
Upvotes: 2