These are chat archives for sbt/sbt-assembly

23rd
Jun 2016
Milosz Tanski
@mtanski
Jun 23 2016 17:29
Hi there, how do I deal with merge strategy and subprojects. So the merge strategy is inherited.
I've read the documentation (github) and tried a bunch of stuff locally, but it doesn't seam to work.
David Kelly
@kellydavid
Jun 23 2016 20:01

Hi @mtanski the README file for the sbt-assembly plugin isn't very clear about this for a new sbt user as I was when I first started using the plugin. However, after reading a lot about sbt (I recommend getting a copy of sbt in action) I was able to figure it out. You could try something like this (assuming you have a build.sbt file in the root of your project):

// Project Definitions
lazy val myproject = (project in file("."))
  .aggregate(core, subProjectOne, subProjectTwo)
  .disablePlugins(sbtassembly.AssemblyPlugin)
  .settings(baseSettings ++ Seq(name := "my-project"))

lazy val core = (project in file("core"))
  .disablePlugins(sbtassembly.AssemblyPlugin)
  .settings(coreSettings)

lazy val subProjectOne = (project in file("sub-project-one"))
  .dependsOn(core)
  .settings(subProjectOneSettings)

lazy val subProjectTwo = (project in file("sub-project-two"))
  .dependsOn(core)
  .settings(subProjectTwoSettings)

// Gets current git commit ID
lazy val gitCommit: String = sys.process.Process("git rev-parse HEAD").lines_!.head

lazy val baseSettings = Seq(
  organization := "com.mycompany",
  scalaVersion := "2.11.7",
  version := "1.0-SNAPSHOT"
)

// Settings common to most modules
lazy val commonSettings = baseSettings ++ Seq(
  libraryDependencies ++= Seq(
    // put deps here
  ),
  assemblyMergeStrategy in assembly := {
    case PathList("META-INF", xs@_*) => MergeStrategy.discard
    case PathList("stuff", xs@_*) => MergeStrategy.discard
    case x => MergeStrategy.first
  },
  assemblyJarName in assembly := s"${name.value}-${version.value}-${gitCommit.substring(0, 7)}.jar"
)

// Settings for each project module
lazy val coreSettings = commonSettings ++
  Seq(name := "core")

lazy val subProjectOneSettings = commonSettings ++
  Seq(name := "sub-project-one")

lazy val subProjectTwoSettings = commonSettings ++
  Seq(name := "sub-project-two")

Hope this helps