当前位置: 首页 > 知识库问答 >
问题:

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

濮阳
2023-03-14
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")
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片段I中。

我不知道的事情我在这方面不够熟练,不知道为什么项目有sbt-assembly和sbt-package Manager。我已经对plugins.sbt中的sbt-assembly进行了注释,但仍然遇到了这个问题,所以我现在认为它不是贡献者

    null

共有1个答案

段干楚青
2023-03-14

似乎需要在Project1Project2的设置中为其启用SBTNativePackager

尝试通过添加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也同样如此。

 类似资料: