How to create SBT project with IntelliJ Idea?

There are three basic ways how to create a project – modern versions of IntelliJ can import sbt project out of the box, otherwise you can either use sbt plugin to generate IntelliJ project, or use IntelliJ Scala plugin to create sbt project. Basic features work out of the box using both solutions, some complex builds can have problems, so try other tools to see if it works there.

IntelliJ

IntelliJ IDEA has become so much better these days. The current version (14.0.2) supports sbt projects out of the box with the Scala plugin. Just install the plugin and you should be able to open up Scala/sbt projects without any troubles.

Scala plugin under Plugins in Preferences

With the plugin, just point at a sbt project and IDEA is going to offer you a wizard to open that kind of project.

Import sbt project

IntelliJ Scala Plugin

IntelliJ plugin can be found here
http://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+IntelliJ+IDEA or can be installed directoly from within the IDE using Settings -> Plugins dialog. Afterwards one can just do File -> New Project -> Scala -> SBT based. IntelliJ will generate basic build.sbt, download necessary dependencies and open project.

SBT Plugin

Sbt plugin that generate an idea project based on the sbt files can be found here: https://github.com/mpeltonen/sbt-idea

SBT 12.0+ & 13.0+

Simply add addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2") to your build.sbt; no additional resolvers are needed.

Older Versions:

SBT 0.11+

Create and add the following lines to ~/.sbt/plugins/build.sbt OR PROJECT_DIR/project/plugins.sbt

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

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

Use gen-idea in sbt to create IDEA project files.

By default, classifiers (i.e. sources and javadocs) of sbt and library dependencies are loaded if found and references added to IDEA project files. If you don’t want to download/reference them, use command gen-idea no-classifiers no-sbt-classifiers.


SBT 0.10.1
(according to the plugin author, 0.10.0 won’t work!)

Create and add the following lines to ~/.sbt/plugins/build.sbt:

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

libraryDependencies += "com.github.mpeltonen" %% "sbt-idea" % "0.10.0"

Use gen-idea sbt task to create IDEA project files.

By default, classifiers (i.e. sources and javadocs) of sbt and library dependencies are loaded if found and references added to IDEA project files. If you don’t want to download/reference them, use command gen-idea no-classifiers no-sbt-classifiers.


SBT 0.7

To use it, simply run this from your sbt shell, it will use the plugin as an external program:

 > *sbtIdeaRepo at http://mpeltonen.github.com/maven/
 > *idea is com.github.mpeltonen sbt-idea-processor 0.4.0
 ...
 > update
 ...
 > idea
 ...

You can also add trait in your project definition, as you want:

import sbt._
class MyProject(info: ProjectInfo) extends ParentProject(info) with IdeaProject {
  lazy val mySubProject = project("my-subproject", "my-subproject", new DefaultProject(_) with IdeaProject)
   // ...
}

Leave a Comment