2

Not sure if its possible but i wish to have several main classes and i don't wish to change sbt.build each time before i run sbt assembly

is there a way to pass the mainClass argument while calling assembly ? like: project> assembly -mainClass someApp.scala ?

Thanks

Michal
  • 150
  • 3
  • 13

2 Answers2

3

I would try something like:

sbt "set mainClass in assembly := Some(\"com.some.Class\")" assembly

Basically you should be able to define any key in any build scope with statement like that. Just pay attention to escaping quotes.

Pietrotull
  • 477
  • 4
  • 9
0

So i figured some solution (not actually specifying mainClass in terminal)

i had a project/module (its a sbt multi project) and basically copied the old module with just a few changes including the mainClass

lazy val oldProject = (project in file("modules/old-project"))
...

lazy val newProject = oldProject.copy(
  id = s"${oldProject.id}-new"
).settings(
    mainClass in assembly := Some("someNewApp"),
    assemblyJarName in assembly := "someNew.jar",
    target := file("modules/some-new-project")
  )


lazy val root = (project in file("."))
  .settings(commonSettings)
  .dependsOn(..., oldProject, newProject, ...)
  .aggregate(..., oldProject, newProject, ...)

now i can select the new project/module in sbt and run assembly which produces a jar in the new target folder.

This is basically pretending that there are 2 modules in one.

note: i didn't run the jar yet.

Michal
  • 150
  • 3
  • 13