すずけんメモ

技術メモです

sbtでIntelliJ IDEA用の設定をする

IntelliJ IDEAでscala書く際にsbtでどう設定すればいいか調べた。

sbt-ideaプラグインをいれよう

mpeltonen/sbt-idea https://github.com/mpeltonen/sbt-idea

これをいれればよい。README.mdにも書いてあるとおり、project/plugins.sbtに以下の内容で書いておく。

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")

sbtを実行する。するとインストールされるはず。

-> % sbt
[info] Loading project definition from /Users/hoge/work/HelloScalaNext/project
[info] Updating {file:/Users/hoge/work/HelloScalaNext/project/}default-7007d1...
[info] Resolving com.github.mpeltonen#sbt-idea;1.5.1 ...
[info] Resolving commons-io#commons-io;2.0.1 ...
[info] Resolving org.scala-sbt#sbt_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#main_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#actions_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#classfile_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#io_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#control_2.9.1;0.11.3 ...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving org.scala-sbt#interface;0.11.3 ...
[info] Resolving org.scala-sbt#logging_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#process_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#classpath_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#launcher-interface_2.9.1;0.11.3 ...
[info] Resolving org.scala-lang#scala-compiler;2.9.1 ...
[info] Resolving org.scala-sbt#incremental-compiler_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#collections_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#api_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#persist_2.9.1;0.11.3 ...
[info] Resolving org.scala-tools.sbinary#sbinary_2.9.0;0.4.0 ...
[info] Resolving org.scala-sbt#compile_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#ivy_2.9.1;0.11.3 ...
[info] Resolving org.apache.ivy#ivy;2.2.0 ...
[info] Resolving com.jcraft#jsch;0.1.46 ...
[info] Resolving commons-httpclient#commons-httpclient;3.1 ...
[info] Resolving commons-logging#commons-logging;1.0.4 ...
[info] Resolving commons-codec#commons-codec;1.2 ...
[info] Resolving org.scala-sbt#completion_2.9.1;0.11.3 ...
[info] Resolving jline#jline;0.9.94 ...
[info] Resolving org.scala-sbt#run_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#task-system_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#tasks_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#tracking_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#cache_2.9.1;0.11.3 ...
[info] Resolving org.scala-sbt#testing_2.9.1;0.11.3 ...
[info] Resolving org.scala-tools.testing#test-interface;0.5 ...
[info] Resolving org.scala-sbt#compiler-interface;0.11.3 ...
[info] Resolving org.scala-sbt#precompiled-2_8_2;0.11.3 ...
[info] Resolving org.scala-sbt#precompiled-2_8_1;0.11.3 ...
[info] Resolving org.scala-sbt#precompiled-2_9_2;0.11.3 ...
[info] downloading http://repo1.maven.org/maven2/com/github/mpeltonen/sbt-idea_2.9.1_0.11.3/1.5.1/sbt-idea-1.5.1.jar ...
[info]  [SUCCESSFUL ] com.github.mpeltonen#sbt-idea;1.5.1!sbt-idea.jar (1517ms)
[info] Done updating.
[info] Set current project to hello-scala-next (in build file:/Users/hoge/work/HelloScalaNext/)
>

あとはgen-ideaをsbtコンソール内でやる。

> gen-idea
[info] Creating IDEA module for project 'hello-scala-next' ...
Getting Scala 2.10.2 ...
:: retrieving :: org.scala-sbt#boot-scala
        confs: [default]
        5 artifacts copied, 0 already retrieved (24390kB/912ms)
[info] Updating {file:/Users/hoge/work/HelloScalaNext/}default-e9c649...
[info] Resolving org.scala-lang#scala-library;2.10.2 ...
[info] Done updating.
[info] Resolving org.scala-lang#scala-library;2.10.2 ...
[info] downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.2/scala-library-2.10.2-javadoc.jar ...
[info]  [SUCCESSFUL ] org.scala-lang#scala-library;2.10.2!scala-library.jar(doc) (56921ms)
[info] downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.2/scala-library-2.10.2-sources.jar ...
[info]  [SUCCESSFUL ] org.scala-lang#scala-library;2.10.2!scala-library.jar(src) (2329ms)
[info] Excluding folder target
[info] Created /Users/hoge/work/HelloScalaNext/.idea/IdeaProject.iml
[info] Created /Users/hoge/work/HelloScalaNext/.idea
[info] Excluding folder /Users/hoge/work/HelloScalaNext/target
[info] Created /Users/hoge/work/HelloScalaNext/.idea_modules/hello-scala-next.iml
[info] Created /Users/hoge/work/HelloScalaNext/.idea_modules/hello-scala-next-build.iml

するとこんな感じでidea関連ファイルが生成される。

-> % tree .idea
.idea
├── IdeaProject.iml
├── compiler.xml
├── copyright
│   └── profiles_settings.xml
├── encodings.xml
├── highlighting.xml
├── libraries
│   ├── SBT__org_scala_lang_scala_library_2_10_2.xml
│   ├── SBT__scala_2_10_2.xml
│   ├── SBT__scala_2_9_1.xml
│   ├── scala_compiler.xml
│   └── scala_library.xml
├── misc.xml
├── modules.xml
├── projectCodeStyle.xml
├── scala_compiler.xml
├── scopes
│   └── scope_settings.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml

3 directories, 18 files
-> % tree .idea_modules
.idea_modules
├── hello-scala-next-build.iml
└── hello-scala-next.iml

あとはこのプロジェクトディレクトリをrootとしてIntelliJにimportすればよい。