scalaapache-sparksbtsbt-assemblysbt-plugin

Publish Local generates empty jar in a multi-module SBT project


When I do publishLocal on some modules it works, but for one module it generates empty jar with only META-INF/Manifest.MF . All modules have a standard folder structure src>main>scala . The only difference is this module has no main class and is just a module with a lot of util classes used by other modules.

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

So bar/publishLocal works but fizz/publishLocal generates an empty jar, and then any other project relaying on published local jar of fizz fails.

Edit: Fixed typo of Fuzz to Fizz


Solution

  • So the above issue was only an issue in jenkins and not anywhere else. Fixed that by renaming the variables in build.sbt to PascalCase to match the folder names and then correct jars were created. For e.g.

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