如何在具有多个主电源的单个模块项目中设置sbt-native-packager

我有一个模块客户端 – 服务器项目,每个项目都有一个main.

我正在尝试使用sbt-native-packager为两者生成启动脚本.

项目/ 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)

当我运行client:stage时,使用所有必需的jar创建目录target / universal / stage / lib但是bin目录丢失了.我究竟做错了什么?

辅助问题:设置起始脚本名称的关键是什么?

最佳答案 我建议将项目设置为多模块构建,而不是创建和使用新配置.我尝试了你的多个配置路线,它很快变得毛茸茸.

例如(我为客户端和服务器之间共享的任何内容创建了一个共享项目):

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
)

注意我在客户端和服务器中启用了sbt-native-packager的JavaAppPackaging.

然后运行阶段.

此外,起始脚本名称的键是executableScriptName.

点赞