scala - Suppress main class in sbt-assembly -
in multi-project sbt build, how should 1 explicitly suppress mainclass attribute in sbt-assembly?
i've searched extensively cannot seem find out how prevent main class being set in jar built sbt-assembly in multi-project build.
in single-project build, seems work long there @ least 2 classes might potentially invoked command line:
import sbt._ import keys._ import sbtassembly.plugin._ import sbtassembly.assemblyutils._ import assemblykeys._ object testbuild extends build { lazy val buildsettings = defaults.defaultsettings ++ assemblysettings ++ seq( version := "0.1-snapshot", organization := "com.organization", scalaversion := "2.10.2", mergestrategy in assembly := mergefirst ) lazy val root = project(id = "test-assembly", base = file("."), settings = buildsettings) settings( mainclass in assembly := none ) lazy val mergefirst: string => mergestrategy = { case "reference.conf" | "rootdoc.txt" => mergestrategy.concat case pathlist("meta-inf", xs @ _*) => (xs map {_.tolowercase}) match { case ("manifest.mf" :: nil) | ("index.list" :: nil) | ("dependencies" :: nil) => mergestrategy.discard case ps @ (x :: xs) if ps.last.endswith(".sf") || ps.last.endswith(".dsa") => mergestrategy.discard case "plexus" :: xs => mergestrategy.discard case "services" :: xs => mergestrategy.filterdistinctlines case ("spring.schemas" :: nil) | ("spring.handlers" :: nil) => mergestrategy.filterdistinctlines case _ => mergestrategy.first } case _ => mergestrategy.first } }
however, appears mainclass := none
isn't necessary. in fact, if left there, main class still set in manifest if there 1 candidate class.
unforunately, in multi-project build, not prevent main class being set including additional class dummy entry-point.
after lot of fiddling around, found prevent main class being set setting mainclass
none
in several scopes independently. in particular, trick:
mainclass in assembly := none mainclass in packagebin := none nainclass in compile := none mainclass in run := none
i not find requirement stated in documentation , cannot figure out why necessary. setting mainclass in (compile, run) := none
not work. need scoped separately.
is proper way manually suppress main class or missing something? if not bug, think should documented somewhere, given behavior not consistent between single- , multi-project builds.
main-class
, other attributes in jar determined packageoptions in assembly
, remove package.mainclass
follows:
lazy val root = project(id = "test-assembly", base = file("."), settings = buildsettings) settings( packageoptions in assembly ~= { os => os filternot {_.isinstanceof[package.mainclass]} } )
this should work multi-project builds too.
note: sbt-assembly caches output jar based on metadata of source input, testing settings around assembly
requires clearing cache calling clean
.
Comments
Post a Comment