How to setup sbt-native-packager in a single module project with multiple mains

杀马特。学长 韩版系。学妹 提交于 2019-12-23 11:57:07

问题


I have a single module client-server project with a main for each.

I'm trying to use sbt-native-packager to generate start-script for both.

project/P.scala

object Tactic extends Build {

  lazy val root =
    (project in file(".")).
    configs(Client, Server)
    .settings( inConfig(Client)(Defaults.configTasks) : _*)
    .settings( inConfig(Server)(Defaults.configTasks) : _*)

  lazy val Client = config("client") extend Compile
  lazy val Server = config("server") extend Compile

}

build.sbt

mainClass in Client := Some("myProject.Client")

mainClass in Server := Some("myProject.Server")

enablePlugins(JavaAppPackaging)

When I run client:stage the directory target/universal/stage/lib is created with all the necessary jars but the bin directory is missing. What am I doing wrong?

Subsidiary question: what is the key to set the starting script name?


回答1:


I would recommend setting up your project as a multi-module build, instead of creating and using new configurations. I tried your multiple configuration route and it gets hairy very quickly.

For example (I created a shared project for anything shared between client & server):

def commonSettings(module: String) = Seq[Setting[_]](
  organization := "org.tactic",
          name := s"tactic-$module",
       version := "1.0-SNAPSHOT",
  scalaVersion := "2.11.6"
)

lazy val root = (project in file(".")
  settings(commonSettings("root"))
  dependsOn (shared, client, server)
  aggregate (shared, client, server)
)

val shared = (project
  settings(commonSettings("shared"))
)

val client = (project
  settings(commonSettings("client"))
  enablePlugins JavaAppPackaging
  dependsOn shared
)

val server = (project
  settings(commonSettings("server"))
  enablePlugins JavaAppPackaging
  dependsOn shared
)

Note I'm enabling sbt-native-packager's JavaAppPackaging in the client and server.

Then run stage.


Also, the key for the starting script name is executableScriptName.



来源:https://stackoverflow.com/questions/29729134/how-to-setup-sbt-native-packager-in-a-single-module-project-with-multiple-mains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!