3
votes

I have a project with a few subprojects, and many dependencies, One subproject will have most development (app) and generating the full jar takes time. So I want to split the fat-jar generation into 2 jars:

  • deps a fat-jar
  • app a lean-jar

I was hoping to create a deps project like:

lazy val deps = (project in file("deps"))
 .settings(
   libraryDependencies ++= commonDependencies,
   assemblyJarName in assembly := "deps.jar",
   assemblyMergeStrategy in assembly := {
     case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard
     case m if m.toLowerCase.matches("meta-inf.*\\.sf$") => MergeStrategy.discard
     case m if m.toLowerCase.startsWith("meta-inf/services/") => MergeStrategy.filterDistinctLines
     case m if m.toLowerCase.endsWith(".dct") => MergeStrategy.first
     case "reference.conf" => MergeStrategy.concat
     case _ => MergeStrategy.first
   }
).dependsOn(
   measurement,
   streaming,
   domain
)

and my app project like:

lazy val app = (project in file("my-app"))
  .settings(clientEventSettings)
  .settings(noPublishSettings)
  .settings(
    assemblyJarName in assembly := "my-app.jar",
    assemblyMergeStrategy in assembly := {
      case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard
      case m if m.toLowerCase.matches("meta-inf.*\\.sf$") => MergeStrategy.discard
      case m if m.toLowerCase.startsWith("meta-inf/services/") => MergeStrategy.filterDistinctLines
      case m if m.toLowerCase.endsWith(".dct") => MergeStrategy.first
      case "reference.conf" => MergeStrategy.concat
      case _ => MergeStrategy.first
    })
  .dependsOn(  //<- but do not package??
    measurement,
    streaming,
    messagingDomain,
    messagingKafkaToolkit,
    domain,
    analyticsWebtrekk,
    commons
  )

compile-wise my-app project is dependent on the other subprojects (deps) but it should be scope provided because I don't want it to be packaged by sbt-assembly.

I'm going to try using the libraryDependencies, but I think that means cloning the commonDependencies, all with scope provided.

1

1 Answers

0
votes

The readme of sbt-assembly provides the answer: In the section: Splitting your project and deps JARs

assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false, includeDependency = false)