IntelliJ IDEA: Configure for Scala and SBT


Versions

  1. CentOS 6.3
  2. Oracle Java JDK 1.6
  3. Scala 2.10.1
  4. SBT 0.12
  5. IntelliJ IDEA Community 12.0.4

Prerequisites

  1. CentOS 6: Install IntelliJ IDEA

Install Plugins

Add the SBT and Scala language plug-ins:

  1. Click Configure: intellij_idea_configure.png
  2. Click Plugins: intellij_idea_plugins.png
  3. Click Browse repositories: intellij_idea_browse_repositories.png
  4. Click the search box and enter “scala”: intellij_idea_plugin_search_box.png
  5. Select both SBT and Scala Language plugins by shift-left clicking on them
  6. Right click on one of the plugins and select Download and Install intellij_idea_download_and_install.png
  7. Click Install then Close then Ok and restart IntelliJ IDEA

Try out SBT Console

  1. After IntelliJ IDEA restarts, either load an existing Scala project or create an empty Scala project
  2. Click on SBT console in lower left corner: intellij_idea_sbt_console.png
  3. Click on the play icon: intellij_idea_sbt_play.png
  4. IntelliJ will download SBT and Scala jars then display the SBT command-line: intellij_idea_sbt_command-line.png

Configure SBT gen-idea command for the current user

  1. Make directories if missing:
  2. Add the SBT plugin for generating IntelliJ IDEA project files, edit ~/.sbt/plugins/build.sbt:
  3. Load ~/.sbt/plugins/build.sbt, by entering reload in the SBT console:
  4. Use any existing build.sbt or create a blank build.sbt (see SBT: Standard build.sbt for Scala) then invoke at SBT console:
  5. After downloads complete and generation is complete, click Ok and IntelliJ will restart

    Note

    the SBT plugin will automatically download the appropriate Scala compiler version. This is a separate instance from any instance of the Scala compiler you may have installed already.

5 thoughts on “IntelliJ IDEA: Configure for Scala and SBT

  1. Aaron

    Hi Lance,

    Thanks for the nice ‘get started’ series, very simple to follow and perfect for getting started on these very interesting technologies.

    I have a question about item 16 on this page, where you write:
    Use any existing build.sbt or create a blank build.sbt then invoke at sbt console:

    I don’t know my way around SBT, so this probably will more make sense in the coming weeks.. But what exactly is going on in this step..?

    Cheers,
    Aaron

    Reply
    1. Lance Post author

      Hi Aaron,

      Thanks for your feedback. I added a link to a standard build.sbt that can be used on step 16.

      Sbt uses a build file named ‘build.sbt’ to get the options necessary to build your project. Once you have the IntelliJ IDEA sbt plugin configured and have a build.sbt created, the sbt command ‘gen-idea’ will cause sbt to generate all of the project files for IntelliJ IDEA. After that you can open the project in IntelliJ IDEA.

      -Lance

      Reply
  2. Alex

    How do I make Idea use “sbt compile” instead of its own built-in compiler which can be called by Ctrl+F9 or Build -> Make Project? Of course, I can say “compiler” in sbt console, but I would like do that by pressing Ctrl+F9 or by pressing Make Project icon.

    Reply
    1. Lance Post author

      Hi Alex! I don’t know the answer to this one. I never use IntelliJ’s built in compiler. I always use the sbt console.

      -Lance

      Reply

Leave a Reply to Lance Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">