sksamuel
sksamuel

Reputation: 16387

SBT assembly skip some subprojects

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.

Upvotes: 13

Views: 4258

Answers (3)

tjarvstrand
tjarvstrand

Reputation: 1038

Actually, the sbt settings do work, but you have to read the code to find the correct way to use them. I was able to accomplish what you want by setting:

assembleArtifact in packageBin := false,
assembleArtifact in assemblyPackageScala := false,
assembleArtifact in assemblyPackageDependency := false,

Upvotes: 0

Erik van Oosten
Erik van Oosten

Reputation: 1738

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.)

Upvotes: 4

tobym
tobym

Reputation: 1344

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)))
}

Upvotes: 2

Related Questions