追記:この記事を最初に書いたときには存在しませんでしたが、このstandard projectを0.11系に対応させたものがこれ https://github.com/twitter/sbt-package-dist のようです
twitter さんが、わりとどんなプロジェクトでも標準で使っているこれ
https://github.com/twitter/standard-project/
をだらだらと読んで、なんとなく感想を書いてみるエントリ。実際自分が試したわけではなく、読んでみて「なんとなくこういうことしてるんだろうなぁ」っていう妄想が入っているので、正確じゃない部分があるかもしれません。*1このblog書いてる時点で最新っぽい 1.0.0のtag
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0
を読みます。
このpluginは、たとえば
gizzard https://github.com/twitter/gizzard/blob/version-3.0.0-beta4/project/plugins/Plugins.scala#L5
ostrich https://github.com/twitter/ostrich/blob/version-4.0.1/project/plugins/Plugins.scala#L5
finagle https://github.com/twitter/finagle/blob/version-1.2.3/project/plugins/Plugins.scala#L5
flockdb https://github.com/twitter/flockdb/blob/version-1.8.0-alpha3/project/plugins/Plugins.scala#L5
util https://github.com/twitter/util/blob/version-1.8.1/project/plugins/Plugins.scala#L5
などなど、かなり多くのプロジェクトで使われています。ただ、twitterが使っているのは、sbtの0.7系で、最近ほぼ主流になっているsbtの0.10系や0.11系とpluginの互換性はないので、べつに「これ読んでみんなで使おうぜ!」っていうものではないです。そもそも、twitter独自の設定とかタスクとかベタ書きしてあったりもして、色々とあれです。まぁだからこそ読んでいて面白いので読んでみます
build.properties の項目の自動生成
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/BuildProperties.scala#L20-25
ここで
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/BuildProperties.scala#L33
"Writes a build.properties file into the target folder"
って書いてあるから、jarと一緒にデプロイまでして、実行時に使うか、buildした際の情報をあとで調べられるようにするためだろうか?
共通して参照するリポジトリの定義
この standard project に限らないですが、ローカルの URL までかいてありますね twitter さんのライブラリは
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/DefaultRepos.scala#L15-38
Ensime っていう emacs 用のファイルの生成機能
最近は twitter も IDEA 使ってるのかな URL 前からだっけ?
2012-01-12 10:09:29 via web
結構あるな URL IDEA 使ってるのか
2012-01-12 10:31:39 via web
gitの操作
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/GitHelpers.scala
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/GithubPublisher.scala
project/release.properties とか project/build.properties などはコミットするって決まっているとかそんな感じで、定型的な操作はsbtからも可能なようになっている感じ?そもそも、release.propertiesっていうファイルも、sbt標準ではなく、twitterさんが独自に自動生成しているものですねたしか
github へ publish
IntegrationSpec
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/IntegrationSpecs.scala
IntegrationSpec ・・・は、まぁ結合テストってことだろうけど、ちょっとソース見ただけじゃ、具体的にどんな機能があるのかよくわからないな
本番にデプロイ用の(?)、jarをまとめたり、起動のスクリプト作る処理
Versionの管理
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/PimpedVersion.scala
これ自動で管理って、少なくとも他のもので自分はあまり見たことないんですが、だいぶ徹底してますね。
"minor versionの部分をインクリメント" や "major versionの部分をインクリメント" というかたちで sbt から操作できるようにしてるみたいです
dependency とか調べたりする独自コマンドがいっぱい・・
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/ProjectDependencies.scala
なんでこんなにあるんだろう・・・。初期の頃から sbt を使っていて、最初は機能少なかったから、どんどん独自に追加していったらこうなったんだろうか。現在では標準でついていそうなものまで再実装してるような
localのmavenにpublish
api doc とかの document の生成とpublish
このあたり↓
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/PublishSite.scala#L203
に"gh-pages"って文字が見えますが、多くのtwitterのライブラリは、githubのgh-pagesにドキュメントが置かれています。例↓
http://robey.github.com/kestrel/
http://robey.github.com/kestrel/doc/main/api/index.html
http://twitter.github.com/finagle/
http://twitter.github.com/finagle/api/finagle-kestrel/index.html
http://twitter.github.com/finagle/api/finagle-core/index.html
http://twitter.github.com/util/
http://twitter.github.com/util/util-core/target/site/doc/main/api/index.html
ドキュメント生成して、それをgh-pagesのbranchへコミットもある程度自動化してるみたいです。でも、微妙にディレクトリ構成統一感なかったり、gh-pagesがないプロジェクト*2もあるし、どのくらいこの部分の機能が使われているのかは不明
SVNの操作
https://github.com/twitter/standard-project/blob/org=com.twitter,name=standard-project,version=1.0.0/src/main/scala/com/twitter/sbt/SubversionPublisher.scala
あれだけ色々とgithubで公開してるわけですが、社内でSVNもつかってるみたいですね。それとも今はほとんどSVN使ってないけれど、とりあえず残ってるのかなんなのか