Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT assembly skip some subprojects

Tags:

sbt

I have an sbt multi module project which is configured for sbt assembly. In this project i want to skip the fat jar generation for sub projects that are not intended to be executable in order to speed the build up. But I'm not sure how this is done.

like image 200
sksamuel Avatar asked Jan 20 '15 10:01

sksamuel


2 Answers

If you use a build.sbt file you can disable the assembly plugin for a module as follows:

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

This also works for the root module:

lazy val `project-name` = (project in file("."))
  .disablePlugins(sbtassembly.AssemblyPlugin)
  .aggregate(`module-1`, `module-2`)
  .settings(
    ...
  )

(Answer found thanks to @tobym 's comment in the other answer.)

like image 80
Erik van Oosten Avatar answered Jun 08 '23 16:06

Erik van Oosten


Just don't include the assembly settings in the submodules that don't require it.

For example, using sbt 0.13.5 and sbt-assembly 0.11.2, here is a multimodule project. If you run assembly in root, just the "app" project will be made into a fat jar.

project/Build.scala

import sbt._
import Keys._
import sbtassembly.Plugin.assemblySettings

object MyApp extends Build {

  lazy val root = Project("root", file(".")).aggregate(common, app)

  lazy val common = Project("common", file("common"))

  lazy val app = Project("app", file("app")).settings(assemblySettings: _*).dependsOn(common)

}

common/src/main/scala/com/example/common/Hello.scala

package com.example.common

object Hello {
  def hello(name: String): String = s"Hello, $name"
}

app/src/main/scala/com/example/hello/App.scala

package com.example.hello

import com.example.common.Hello._

object Main extends App {
  println(hello(args(0)))
}
like image 21
tobym Avatar answered Jun 08 '23 14:06

tobym