LoginSignup
3
1

More than 5 years have passed since last update.

sbt-native-packager メモ

Last updated at Posted at 2017-02-01
  • Scala アプリを起動スクリプトを付けてパッケージ化してくれる。
  • Windows, Mac, Linux(deb, rpm) に対応している。(Universal(zip) しか試していない)

設定

project/plugins.sbt に追加

project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0-M8")

build.sbt に追加

build.sbt
lazy val root = (project in file("."))
  .enablePlugins(JavaAppPackaging)
  .settings(
    ...
  )

実行

  • stage コマンドで target/universal/stage 配下に必要なファイルがコピーされる。(実行しなくても良い)
  • universal:packageBin コマンドで target/universal/"name"-"version".zip が作成される。(変更可能)

メモ

  • src/universal 配下のファイルはディレクトリ構成含めてtopDirectory 配下にコピーされる。
  • 個別にファイルを追加する場合は mappings を使う

マニュアルを読んでも mappings の記載場所がわからなかったので、試行錯誤した結果以下のようになった。

以下の設定で baseDirectory 配下の README を doc/README に配置する。
project().mappings や settings() の中に記載したらエラーになった。

build.sbt
lazy val root = (project in file("."))
  .enablePlugins(JavaAppPackaging)
  .settings(
    ...
  )

mappings in Universal += {
  file("README") -> "doc/README"
}

マニュアルにある以下の設定はエラーになる。
package-zip-tarball => packageZipTarball が正しいと思われる。

mappings in Universal in package-zip-tarball += file("README") -> "README"
mappings in Universal in packageZipTarball += file("README") -> "README"

mappings について

http://www.scala-sbt.org/0.13/docs/Mapping-Files.html
http://www.scala-sbt.org/0.13/docs/Paths.html

※ 正規表現でも指定できるはずだが試していない。

mappings の型は Seq[(File, String)]、PathFinder は File and Seq[File] を返す。
pair メソッドから Seq[(File, String)] を作れるとあるが、よくわからない。

確認

show universal:packageZipTarball::mappings
mappings in Universal ++= (baseDirectory.value / "config" * "*" get) map
  (x => x -> ("config/" + x.getName)),
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1