在 SBT 中为 sbt-native-packager 的 packageMappings 构建路径 [英] Building paths in SBT for the packageMappings of the sbt-native-packager

查看:61
本文介绍了在 SBT 中为 sbt-native-packager 的 packageMappings 构建路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SBT 非常陌生,需要为我的一个项目创建一个 RPM 包.RPM 只包含 1 个文件,它是由 sbt-onejar 插件创建的一个 jar).我想使用 sbt-native-packager 插件并在/project 目录下创建了一个 Packagin.scala 文件,如下所示:

I am very new to SBT and need to create a RPM package for one of my project. The RPM contains only 1 file, which is a one-jar created by the sbt-onejar plugin). I want to use sbt-native-packager plugin and have created a Packagin.scala file under the /project directory like this:

object Packaging {
  val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ mapGenericFilesToLinux ++ Seq(

    maintainer := "Team",
    packageSummary := "Summary",
    packageDescription := """Description""",

    mappings in Universal += {
      file("target/scala-2.10/projectname_2.10-0.1-one-jar.jar") -> "/opt/projectname/projectname-0.1.jar"
    },

    linuxPackageMappings in Rpm <+= (baseDirectory) map { _:File =>
      (packageMapping(file("target/scala-2.10/projectname_2.10-0.1-one-jar.jar") -> "/opt/projectname/projectname-0.1.jar")
        withUser "someusr" withGroup "somegroup" withPerms "0755")
    },

    name in Rpm := "projectname",
    version in Rpm <<= version apply { sv => sv split "[^\\d]" filterNot (_.isEmpty) mkString "." },
    rpmRelease := "1",
    rpmVendor := "Vendor",
    rpmUrl := Some("url"),
    rpmGroup := Some("group"),
    rpmLicense := Some("BSD")
  )
}

1) 我不想硬编码文件名.而不是 "target/scala-2.10/projectname_2.10-0.1-one-jar.jar" 我需要一种使用现有 SettingKey 的方法,即 target + "scala-" + scalaVersion+ "/" + 名称 + "_" + scalaVersion + "-" + 版本 + "-one-jar.jar" - 你是怎么做的=

1) I don't want to hardcode the file names. Instead of having "target/scala-2.10/projectname_2.10-0.1-one-jar.jar" I need a way to use existing SettingKey's, i.e. target + "scala-" + scalaVersion + "/" + name + "_" + scalaVersion + "-" + version + "-one-jar.jar" - how do you do this=

2) 对于值 rpmRelease :="1" 我想使用系统属性,即在 Maven 中我会做 ${rpm.buildNumber},如何这在 SBT 中有效吗?

2) For the value rpmRelease := "1" I want to use a System property, i.e. in Maven I would do ${rpm.buildNumber}, how does that work in SBT?

3) 关于 sbt-native-packager 插件,有什么我应该做的更好的吗?

3) Is there anything I should do better in regards to the sbt-native-packager plugin?

推荐答案

1) 您应该始终在 sbt 中使用 task output 而不是原始文件系统查找.因为 sbt 是并行执行的,如果你不对任务的输出设置显式依赖,那么你不能保证在你运行任务之前会创建一个文件.

1) You should always use task output in sbt rather than raw filesystem lookups. Because sbt has parallel execution, if you don't put an explicit dependency on the output of a task, then you have no guarantee that a file will be created before you run your task.

在这种情况下,您希望将包映射行更改为如下所示:

In that vein you want to change your package mappings line to be something like this:

mappings in Universal += {
  oneJar.value -> "/opt/projectname/projectname-0.1.jar"
},

oneJar 键在 onejar 插件.

2) Sbt 仅使用 scala 作为构建语言,因此您可以类似地获取系统属性(但也请提供默认值):

2) Sbt just uses scala for the build language, so you can grab system properties similarly (but please also provide a default):

rpmRelease := Option(sys.props("rpm.buildNumber")) getOrElse "1"

3) 现在您正在定义一个通用包并且在 Rpm 中用不同的用户重新定义同一个文件.mapGenericFilesToLinux 设置仍然缺少一些自定义设置,但是如果您不创建通用发行版,您应该能够删除这些设置并直接配置您的 linux 包:

3) Right now you're defining a generic package and redefining the same file in the Rpm with a different user. The mapGenericFilesToLinux settings still lack a few customizations, but if you're not creating universal distributions, you should be able to drop that bit of settings and instead directly configure your linux package:

linuxPackageMappings in Rpm <+= (oneJar) map { jar:File =>
  (packageMapping(jar -> "/opt/projectname/projectname-0.1.jar")
    withUser "someusr" withGroup "somegroup" withPerms "0755")
},

这篇关于在 SBT 中为 sbt-native-packager 的 packageMappings 构建路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆