SBT程序集

时间:2018-01-16 14:36:41

标签: scala sbt sbt-assembly sbt-plugin

我正在为AWS Lambda创建jar来运行作业任务。目前我的build.sbt文件看起来像这样:

lazy val commonSettings = Seq(...)

lazy val core = project
    .settings(commonSettings: _*)

lazy val job = project
    .settings(commonSettings: _*)
    .dependsOn(core)

lazy val service = project
    .settings(commonSettings: _*)
    .settings(
        mainClass in assembly := Some("io.example.service.Lambda"),
        assemblyJarName in assembly := "lambda.jar"
    )
    .dependsOn(core)

运行sbt assemblyservice模块组装到我的API的jar中,并且工作正常。然而,模块job将有多个Main类(一个pr。作业),当我运行sbt assembly job时,service模块也被组装(即使它不依赖于)

如何将我的设置配置为仅在需要时组装job模块,并将各个mainClasses指定为单独组装的jar?

2 个答案:

答案 0 :(得分:3)

mainClass in assembly中设置job以定义要使用的主类,并运行job/assembly以组装作业程序集jar。

答案 1 :(得分:0)

您需要通过显式设置属性来覆盖构建时的默认主类。

sbt "; set mainClass in assembly := Some("another/class"); job/assembly"

不确定这是一个好习惯,但也可以为每个作业定义一个具有正确主类集的子项目。

lazy val job1 = project
    .settings(commonSettings: _*)
    .settings(
        mainClass in assembly := Some("io.example.service.Lambda"),
        assemblyJarName in assembly := "lambda.jar"
    )
    .dependsOn(core)

lazy val job2 = project
    .settings(commonSettings: _*)
    .settings(
        mainClass in assembly := Some("io.example.service.Lambda2"),
        assemblyJarName in assembly := "lambda2.jar"
    )
    .dependsOn(core)