LoginSignup
3
3

More than 5 years have passed since last update.

sbt のマルチプロジェクトを生成するための giter8 テンプレート

Last updated at Posted at 2014-11-03

を作りました。

  • アプリケーションからはライブラリを参照できる
  • ライブラリからはアプリケーションを参照できない

というよくある二層構成を想定したものです。

##使い方

例として sample ディレクトリを用意します。

mkdir sample
cd ./sample
git clone https://github.com/x7c1/Slate.git

現在のディレクトリ構成はこんな感じです。

  • /sample
    • /Slate

あとはこのテンプレートを g8 に指定してプロジェクトの情報を入力すれば

g8 file://Slate/slate-template/

organization [org.example]: beerlover         
name [Slate Application]: Beer Apps       
app_prefix [slate]: malt

Template applied in ./beer-apps

もうプロジェクトの生成完了です。

find ./beer-apps -type f
./beer-apps/.gitignore
./beer-apps/malt-app/src/main/scala/beerlover/malt/app/BeerApps.scala
./beer-apps/malt-lib/src/main/scala/beerlover/malt/lib/MaltLibrary.scala
./beer-apps/malt-lib/src/test/scala/beerlover/malt/lib/MaltLibraryTest.scala
./beer-apps/project/MaltBuild.scala

テストもきちんと通ります。

cd beer-apps
sbt malt-lib/test
...
[info] MaltLibrary$ should
[info] + create message
[info] 
[info] Total for specification MaltLibraryTest
[info] Finished in 17 ms
[info] 1 example, 0 failure, 0 error
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 7 s, completed 2014/11/03 19:36:49

もちろんこのライブラリを呼ぶアプリケーションも問題なく実行できます。

sbt malt-app/run
...
hello, BeerApps!
[success] Total time: 5 s, completed 2014/11/03 19:40:20

サブプロジェクトを追加するときは

さっきの sample ディレクトリで slate-template-sub を指定すればおkです。

g8 file://Slate/slate-template-sub/
Create sub-project for sbt

organization [org.example]: beerlover
name [Slate Application]: Beer Apps
sub_project [sub]: stout
app_prefix [slate]: malt

Template applied in ./beer-apps

これで(ビルド定義以外は)同じように作られてるのを確認できます。

find ./beer-apps/malt-stout -type f
./beer-apps/malt-stout/src/main/scala/beerlover/malt/stout/MaltStout.scala
./beer-apps/malt-stout/src/test/scala/beerlover/malt/stout/MaltStoutTest.scala

注意

  • サブプロジェクトを追加したらビルド定義にも更新が必要です。
    • 残念ながらここは手動で追記する必要があります…。

リポジトリ

3
3
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
3