gpt4 book ai didi

scala - 如何在多个项目中使用 sbt-native-packager

转载 作者:行者123 更新时间:2023-12-01 23:13:26 24 4
gpt4 key购买 nike

我正在将几个大型 scala 项目合并为一个。目前他们使用剪切和粘贴(不是很多代码)共享代码,我正在制作它以便有一个通用的实用程序 jar。这些项目大部分部署在亚马逊云上,使用 sbt-native-packager 打包

我的问题是我不知道如何为 sbt native manager 配置多个项目。我也不是很熟悉它,在完成所有初始工作后才进入该项目。

我已将问题减少到我能解决的最小问题。在 https://github.com/stave-escura/multiprojectissue.git 有一个 git repo这说明了问题

在 project/plugins.sbt 中,重要的几行是

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")

build.sbt 太长,放在这里,但它的粗略形状是
import com.typesafe.sbt.SbtNativePackager
import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging

enablePlugins(SbtNativePackager)

enablePlugins(JavaServerAppPackaging)

lazy val commonSettings = Seq(
...
scalaVersion := "2.11.8",
assemblyJarName in assembly := s"${name.value}.jar",
assemblyMergeStrategy in assembly := {
case "BUILD" => MergeStrategy.discard
case other => MergeStrategy.defaultMergeStrategy(other)
}
)

lazy val project1Settings = commonSettings ++ Seq(
rpmVendor := "someOrganisation",
packageDescription in Rpm := "Some description1",
rpmLicense := Some("Copyright 2016 someOrganisation. All rights reserved."),
rpmRequirements := Seq(
"java-1.8.0-openjdk"
),
version in Rpm := "1",
rpmRelease := version.value,
rpmDaemonLogFile := s"${name.value}.log",
daemonUser in Linux := "someUserName",
daemonGroup in Linux := (daemonUser in Linux).value,
rpmPost := Some(
"""|chkconfig --add someService1
|chkconfig someService1 on
""".stripMargin),
linuxPackageMappings ++= Seq() // <--- line 53
)


lazy val project2Settings = commonSettings ++ Seq(
identical to project 1 settings except
packageDescription in Rpm := "Some description2",
rpmPost := Some(
"""|chkconfig --add someService2
|chkconfig someService2 on
""".stripMargin),
linuxPackageMappings ++= Seq() // <--- line 72
)

lazy val project1 = (project in file("components/service1")).settings(project1Settings: _*)

lazy val project2 = (project in file("components/service2")).settings(project2Settings: _*)

在实际项目中,linuxPackageMappings 相当复杂,是我的问题。它们在项目之间有所不同。当我将 build.sbt 加载到 sbt 时,我得到了错误
References to undefined settings: 

project2/*:linuxPackageMappings from project2/*:linuxPackageMappings (~/git/multiprojectissue/build.sbt:72)

project1/*:linuxPackageMappings from project1/*:linuxPackageMappings (~/git/multiprojectissue/build.sbt:53)

at sbt.Init$class.Uninitialized(Settings.scala:265)
...
at xsbt.boot.Boot.main(Boot.scala)
[error] References to undefined settings:
[error]
[error] project2/*:linuxPackageMappings from project2/*:linuxPackageMappings (/Users/ricep02/git/multiprojectissue/build.sbt:72)
[error]
[error] project1/*:linuxPackageMappings from project1/*:linuxPackageMappings (/Users/ricep02/git/multiprojectissue/build.sbt:53)

第 53 和 72 行标记在我上面包含的 build.sbt 代码段中。

我不知道的事
我在这方面不够熟练,不知道为什么该项目有 sbt-assembly 和 sbt-package manager。我已经从 plugins.sbt 中评论了 sbt-assembly 并且仍然遇到这个问题,所以我现在不认为它是有贡献的

我尝试过的事情
我尝试将子项目设置放入与实际组件关联的 build.sbt 文件中。我得到同样的问题。
我还仔细查看了示例项目,例如 https://github.com/muuki88/sbt-native-packager-examples/tree/master/multi-module-build ,并阅读了 http://www.scala-sbt.org/sbt-native-packager/ 上的文档非常小心,虽然我对它没有“经验”:只是在“阅读文档”级别。我还查看了诸如 How to setup sbt-native-packager in a single module project with multiple mains 之类的问题。和 How to create a basic project setup using sbt-native-packager

有用的东西
将 packageMappings 留在 build.sbt 的“主体”中不会导致“sbt 加载问题”,但我还不知道它是否会真正构建包!

软件栈
  • 操作系统:MacOs
  • Java:1.8.0_74-b02
  • 斯卡拉:2.11.8
  • sbt: 0.13.8
  • sbt-native-packager 1.0.6
  • 最佳答案

    它看起来像 SbtNativePackager需要为 project1 启用和 project2在他们的设置中。

    尝试通过添加 enablePlugins(SbtNativePackager) 来修改您的设置:

    lazy val project1Settings = commonSettings ++ Seq(
    rpmVendor := "someOrganisation",
    packageDescription in Rpm := "Some description1",
    rpmLicense := Some("Copyright 2016 someOrganisation. All rights reserved."),
    rpmRequirements := Seq(
    "java-1.8.0-openjdk"
    ),
    version in Rpm := "1",
    rpmRelease := version.value,
    rpmDaemonLogFile := s"${name.value}.log",
    daemonUser in Linux := "someUserName",
    daemonGroup in Linux := (daemonUser in Linux).value,
    rpmPost := Some(
    """|chkconfig --add someService1
    |chkconfig someService1 on
    """.stripMargin),
    enablePlugins(SbtNativePackager),
    linuxPackageMappings ++= Seq() // <--- line 53
    )

    项目 2 也是如此。

    我建议你买一本像“SBT in Action”这样的书来帮助你开始使用“简单”的构建工具。

    关于scala - 如何在多个项目中使用 sbt-native-packager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37916987/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com