【问题标题】:how to define multi-project build with sbt-native-packager that creates an RPM for each sub-project如何使用为每个子项目创建 RPM 的 sbt-native-packager 定义多项目构建
【发布时间】:2016-07-16 23:13:03
【问题描述】:

在我看到的关于多模块构建和 sbt-native-packager 的所有示例中,它们都将子项目聚合到一个包中。我有子项目,每个子项目都提供微服务。我相信它们中的每一个都应该有它自己的本机包,但我不知道如何做到这一点并且为所有子项目构建一个命令。

【问题讨论】:

    标签: sbt sbt-native-packager


    【解决方案1】:

    事实证明这很简单。只需为您要打包的每个子项目提供本机打包程序设置,不要在聚合项目中提供任何设置。

    我通过相应地修改https://github.com/muuki88/sbt-native-packager-examples/tree/master/multi-module-build 进行了测试:

    import NativePackagerKeys._
    
    name := "mukis-fullstack"
    
    // used like the groupId in maven
    organization in ThisBuild := "de.mukis"
    
    // all sub projects have the same version
    version in ThisBuild := "1.0"
    
    scalaVersion in ThisBuild := "2.11.2"
    
    // common dependencies
    libraryDependencies in ThisBuild ++= Seq(
        "com.typesafe" % "config" % "1.2.0"
    )
    
    // this is the root project, aggregating all sub projects
    lazy val root = Project(
        id = "root",
        base = file("."),
        // configure your native packaging settings here
    //    settings = packageArchetype.java_server++ Seq(
    //        maintainer := "John Smith <john.smith@example.com>",
    //        packageDescription := "Fullstack Application",
    //        packageSummary := "Fullstack Application",
            // entrypoint
    //        mainClass in Compile := Some("de.mukis.frontend.ProductionServer")
    //    ),
        // always run all commands on each sub project
        aggregate = Seq(frontend, backend, api)
    ) dependsOn(frontend, backend, api) // this does the actual aggregation
    
    // --------- Project Frontend ------------------
    lazy val frontend = Project(
        id = "frontend",
        base = file("frontend"),
        settings = packageArchetype.java_server++ Seq(
           maintainer := "John Smith <john.smith@example.com>",
           packageDescription := "Frontend appplication",
           mainClass in Compile := Some("de.mukis.frontend.ProductionServer")
        )
    ) dependsOn(api)
    
    
    // --------- Project Backend ----------------
    lazy val backend = Project(
        id = "backend",
        base = file("backend"),
        settings = packageArchetype.java_server++ Seq(
            maintainer := "John Smith <john.smith@example.com>",
            packageDescription := "Fullstack Application",
            packageSummary := "Fullstack Application",
            // entrypoint
            mainClass in Compile := Some("de.mukis.frontend.ProductionServer")
        )
    ) dependsOn(api)
    
    // --------- Project API ------------------
    lazy val api = Project(
        id = "api",
        base = file("api")
    

    结果:

    debian:packageBin
    ...misc messages elided...
    [info] dpkg-deb: building package `frontend' in `../frontend_1.0_all.deb'.
    [info] dpkg-deb: building package `backend' in `../backend_1.0_all.deb'.
    

    【讨论】:

    • 看起来 packageArchetype.java_server 已被弃用,我认为最新的 API 将改为在我们希望单独打包的聚合模块上调用 .enablePlugins(JavaAppPackaging)
    【解决方案2】:

    对于刚刚来到这里的人来说,更新的答案可能如下所示:

    lazy val root = (project in file("."))
        .aggregate(common, frontend, backend)
    
    lazy val common = (project in file("common"))
    lazy val frontend = (project in file("frontend"))
       .enablePlugins(JavaServerAppPackaging)
    lazy val backend = (project in file("backend"))
       .dependsOn(common)
       .enablePlugins(JavaAppPackaging)
       .settings(javaPackagingSettings)
    
    lazy val javaPackagingSettings = Seq(
       // follow sbt-native-packager to identify settings you need
    )
    

    说明

    这里是支持上述配置的场景

    • 项目root 是父项目,我们不想打包它。它聚合了其他子项目。
    • Project common 是一种库,我们也不想打包它
    • 项目 backend 依赖于库的 common
    • 项目frontend 是一个独立项目,采用默认配置打包为Java 服务器应用程序

    【讨论】:

    猜你喜欢
    • 2016-12-14
    • 2013-11-25
    • 2013-09-15
    • 2016-10-21
    • 2018-09-29
    • 2013-12-29
    • 2020-03-11
    • 2016-05-19
    • 2014-12-04
    相关资源
    最近更新 更多