Sbt 本机打包程序找不到 SystemdPlugin

Sbt native packager not finding SystemdPlugin

我正在尝试构建一个使用 Systemd 原型的 rpm。但是,我在 build.sbt 中导入时遇到错误。我正在使用 sbt 版本 0.13.11 具体来说,我看到:

build.sbt:3: error: object systemloader is not a member of package com.typesafe.sbt.packager.archetypes

我正在尝试使用 1.1.4 版的 sbt-native-packager。这是我的 plugins.sbt:

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// The Sonatype snapshots repository
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.4")

我的build.sbt:

import com.typesafe.sbt.packager.linux.LinuxSymlink
import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport._
import com.typesafe.sbt.packager.archetypes.systemloader._

scalaVersion := "2.11.7"

name := "systemdtest"

organization := "myTestOrg"

enablePlugins(JavaServerAppPackaging, RpmPlugin, SystemdPlugin)

version := "1.0"

// RPM SETTINGS
rpmVendor := "me"

packageSummary in Linux := "A summary"

packageDescription := "Do some stuff"

rpmRelease := "1"

rpmBrpJavaRepackJars := false

rpmLicense := Some("Copyright this project")

rpmGroup := Some("mygroup")

rpmPrefix := Some("/opt/mypath")

我尝试 运行

时遇到错误
sbt stage

sbt rpm:packageBin

本机打包程序站点 (http://www.scala-sbt.org/sbt-native-packager/archetypes/systemloaders.html) 上的 1.1 文档说使用名为 SystemdPlugin 的自动插件。

然而,这在1.1分支中不存在,并且在1.2分支中引入(在post时是1.2.0M3),但尚未GA。

正确的约定是在您的 build.sbt 中添加一个名为 "serverLoading."

的作业

就我而言,要使用 RPM,我需要将 build.sbt 更改为以下内容:

import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport._
import com.typesafe.sbt.packager.archetypes.ServerLoader

scalaVersion := "2.11.7"

name := "systemdtest"

organization := "myTestOrg"

enablePlugins(JavaServerAppPackaging)

version := "1.0"

// RPM SETTINGS
rpmVendor := "me"

packageSummary in Linux := "A summary"

packageDescription := "Do some stuff"

rpmRelease := "1"

rpmBrpJavaRepackJars := false

rpmLicense := Some("Copyright this project")

rpmGroup := Some("mygroup")

rpmPrefix := Some("/opt/mypath")

//THIS IS THE KEY PIECE!!
serverLoading in Rpm := ServerLoader.Systemd

我通过阅读有关此问题的评论找到了我的解决方案。 https://github.com/sbt/sbt-native-packager/pull/785

sbt native-packager 1.2.0 即将发布(2016 年 11 月)并且 Muki Seiler details this new feature coming form PR 785:

Systemloaders are AutoPlugins now

Previously, the Java Server Application Archetype provided a setting serverLoading where you could define your system loader like this:

import com.typesafe.sbt.packager.archetypes.ServerLoader

serverLoading in Rpm := ServerLoader.Upstart

This adds the necessary configuration files and maintainer scripts (postinst, postun, etc. ) in order to register and start your application.

The biggest problem with the tight coupling between the server archetype and the systemloaders is that it’s hard to add systemloader specific settings without changing a lot in the server archetype.
It’s also a lot harder to reason about the code and the output.

With extra systemloader plugins we open the possibility to

  • 轻松扩展单个系统加载器
  • 有放置通用 systemloader 功能的地方(有一个 SystemLoaderPlugin 负责通用设置)
  • 隔离测试系统加载程序
  • 更好的开发者体验

You enable a systemloader by enabling a concrete systemloader plugin

enablePlugins(SystemdPlugin)