Locked History Actions

sbt/Getting-Started-Summary

サマリ

https://github.com/harrah/xsbt/wiki/Getting-Started-Summaryの訳(2011/10/30時点)

sbtを使うのに理解する必要がある概念としては少数だ。 若干のラーニングカーブはあるものの、positive sideであるし、これらの概念以外にはあまり多く無い(訳注:?)。 sbtは小さなコアコンセプトの上に、すべてを行う。

Getting Startedシリーズのすべてを読んだなら、もう知るべきことを知っているだろう。

sbtのコアコンセプト

Scalaの基本

Scalaの文法に慣れておくことは疑いなく有用だ。Scalaの作者による「Programming in Scala」をおすすめしたい。

.sbtビルド定義

君のビルド定義は、Settingオブジェクトからなる一つの大きなリストであり、 それぞれのSettingは、sbtがタスクを実行する際に用いるキー・値ペアの集合を変換する。 Settingを作成するには、キーに対して、いくつかあるメソッドのうちの一つを使う(:=と<<=メソッドが特に重要だ)。

ミュータブルな状態というものはなく、変換だけだ。例えば、Settingはsbtのキー・値ペアのコレクションを変換して、新しいコレクションを作成する。 その場で変更されるということはない。

それぞれのSettingは特有のタイプを持ち、それはキーによって決定される。 タスクは特別なSettingであり、タスクを起動されるたびに計算を行い、キーの値を生成する。 タスクでないものは、値を一度だけ計算する、ビルド定義がロードされたときに。

スコープ

各キーは、異なるスコープについて異なる値を持ちうる。 スコープには三つの軸がある。コンフィギュレーション、プロジェクト、タスクだ。 スコーピングによって、プロジェクト毎、タスク毎、コンフィギュレーション毎に異なる振る舞いをさせることができる。

コンフィギュレーションとはビルドの種類である。メインのもの(Compile)あるいはテスト用のもの(Test)のような。

プロジェクト軸は「全体ビルド」スコープもサポートしている。

スコープは、より一般的なスコープにフォールバックする、あるいは委譲することがある。

.sbt vs. .scalaビルド定義

  • put most of your settings in build.sbt, but use .scala build definition files to define multiple subprojects, and to factor out common values, objects, and methods. the build definition is an sbt project in its own right, rooted in the project directory.

Plugins are extensions to the build definition

  • add plugins with the addSbtPlugin method in project/build.sbt (NOT build.sbt in the project's base directory).

If any of this leaves you wondering rather than nodding, please ask for help on the mailing list, go back and re-read, or try some experiments in sbt's interactive mode.

Good luck! Advanced Notes

The rest of this wiki consists of deeper dives and less-commonly-needed information.

Since sbt is open source, don't forget you can check out the source code too!