scalaintellij-ideasbtsbt-assemblysbt-idea

SBT assembly : Can you create an assembly jar of just one sub project in Multi project build?


I want to create a fat assembly jar for a sub project without having to generate jars for other projects or the whole global Project. How can I do that?

From https://github.com/sbt/sbt-assembly I see that I can add Main Class or name of the jars for each sub projects, but no way to run it. assembly runs for the main project, not sub projects.

There is a similar question, but the answer there does not solve this issue.

More details below:

I have a standard folder structure for a multi project build.

├── project
│   └── build.properties
│   └── plugins.sbt
├── build.sbt
├── bar
│   └── src
├── fizz
│   └── src
└── foo
    └── src

My plugins.sbt is : addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

My build.sbt is

ThisBuild / name := "My main Project"

ThisBuild / version := "0.1"
ThisBuild / scalaVersion := "2.11.8"

//Modules/Projects
lazy val global = project
  .in(file("."))
  .settings(settings)
  .disablePlugins(AssemblyPlugin)
  .aggregate(
    bar,
    fizz,
    foo
  )

lazy val bar = project
  .settings(
    name := "Bar",
    settings,
    assemblySettings
  )

lazy val fizz = project
  .settings(
    name := "Fizz",
    settings,
    assemblySettings
  )

lazy val foo = project
  .settings(
    name := "Foo",
    settings,
    assemblySettings
  )
  .dependsOn(
    fizz
  )

lazy val compilerOptions = Seq(
  "-encoding",
  "utf8"
)

lazy val settings = Seq(
  scalacOptions ++= compilerOptions
)

lazy val assemblySettings = Seq(
  assemblyMergeStrategy in assembly := {
    case PathList("META-INF", xs @ _*) => MergeStrategy.discard
    case x =>
      val oldStrategy = (assemblyMergeStrategy in assembly).value
      oldStrategy(x)
  }
)

If I run assembly, in the sbt shell in Intellij it runs assembly for the global project. Now because I have added aggregate to global project it also generates individual jars for all sub projects.

But this takes a lot of time, I want to generate just a Jar of bar which will only give me fat jar for Bar. If I just run assembly on Foo, it will create a fat jar for Foo including Fizz but not Bar. How can this be done?


Solution

  • as per @LuisMiguelMejíaSuárez' s comment following solution works.

    bar/assembly
    

    So <sum-module-name-as-in-build.sbt>/assembly