LoginSignup
20
17

More than 5 years have passed since last update.

Scala製コマンドラインツールをIntelliJ IDEAで書いて公開する

Last updated at Posted at 2014-09-12
  • sbt を使ったプロジェクトを
  • IntelliJ IDEA で書いて
  • Conscript でインストールできるように公開する
  • リポジトリには Github Pages を使う

ひな形を作成する

giter8

https://github.com/n8han/giter8

github 上に公開されているテンプレートをもとにプロジェクトのひな形を作るツール。

$ g8 n8han/conscript
  • Conscript を使ったアプリケーション用のひな形が生成される
  • アプリケーション名、組織名等を対話形式で入力する
  • 組織名は、ドメインを持っていない場合は github の url を使うのが一般的らしい (e.g. com.github.ackintosh)

生成されるひな形

.
├── build.sbt
├── project
│   └── plugins.sbt
└── src
    └── main
        ├── conscript
        │   └── app
        │       └── launchconfig
        └── scala
            └── App.scala

intelliJ IDEA用のプロジェクトファイルを作成

sbt を使ったプロジェクトを intelliJ IDEA にインポートするために、mpeltonen/sbt-idea を使う。

  • ./project/plugins.sbt に追記
/project/plugins.sbt
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
  • プロジェクトファイルを作成
$ sbt gen-idea
  • [File] -> [Import Project...] でインポートする

実装・テストする

  • src/main/scala/App.scala

クラス名等を変えた場合は src/main/conscript/app/launchconfig の name と、ディレクトリ名(app)も変更する。

  • sbt を対話モードで起動してコンパイル等を行う
$ stb
> 
  • コンパイル
> compile
[success] Total time: 0 s, completed 2014/09/11 23:15:34
  • 実行
> run
[info] Running com.github.ackintosh.App
  • テストコードは src/test/scala/ に書く
  • テスト実行
> test
[info] Compiling 1 Scala source to /Users/Ack/Develop/scala/[アプリケーション名]/target/scala-2.11/test-classes...
[info] AppTest:
[info] Run completed in 511 milliseconds.
...
[info] All tests passed.

リポジトリに Github Pages を使う

Github Pagesを作る

  • リポジトリの [Settings] -> [Github Pages] で作れる
  • 表示確認
http://[ユーザ名].github.io/[リポジトリ名]/

ビルド設定

  • ビルドしたファイルの出力先を設定する
$ git checkout gh-pages
$ pwd
[Github Pages を作成したディレクトリ]
build.sbt
publishTo := Some(Resolver.file("アプリケーション名", file("Github Pages を作成したディレクトリ"))(Patterns(true, Resolver.mavenStyleBasePattern)))

ビルド

$ sbt publish
  • publishTo で指定したディレクトリに下記のように出力される
.
└── com
   └── github
       └── [Githubユーザー名]
           └── [アプリケーション名]_2.11
               └── 0.1.0
                   ├── [アプリケーション名]_2.11-0.1.0-javadoc.jar
                   ├── [アプリケーション名]_2.11-0.1.0-javadoc.jar.md5
                   ├── [アプリケーション名]_2.11-0.1.0-javadoc.jar.sha1
                   ├── [アプリケーション名]_2.11-0.1.0-sources.jar
                   ├── [アプリケーション名]_2.11-0.1.0-sources.jar.md5
                   ├── [アプリケーション名]_2.11-0.1.0-sources.jar.sha1
                   ├── [アプリケーション名]_2.11-0.1.0.jar
                   ├── [アプリケーション名]_2.11-0.1.0.jar.md5
                   ├── [アプリケーション名]_2.11-0.1.0.jar.sha1
                   ├── [アプリケーション名]_2.11-0.1.0.pom
                   ├── [アプリケーション名]_2.11-0.1.0.pom.md5
                   └── [アプリケーション名]_2.11-0.1.0.pom.sha1

Github Pages に公開

  • push するだけ
$ git add .
$ git commit -m "release 0.1.0"
$ git push origin gh-pages

Conscript用設定

[repositories]
  gh-pages:http://ackintosh.github.io/[Github Pages を作成したリポジトリ名]/

Github に push しておく。

これで Github Pages にアップしたアプリケーションを Conscript を使ってインストールできるようになった。

インストール確認

$ cs [Githubユーザー名]/[アプリケーション名]
Conscripted [Githubユーザー名]/[アプリケーション名] to /Users/xxx/bin/[アプリケーション名]

Link

Scala環境構築

a command line tool to apply templates defined on github

This is a tool for installing and updating Scala software programs.

A simple-build-tool (sbt) plugin/processor for creating IntelliJ IDEA project files

20
17
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
20
17