How to setup IntelliJ Idea for Scala SBT projects

This is something I need quite often for Coursera because I can’t stand Eclipse. Really, I can’t. I suppose there’s no accounting for taste, right, so don’t think I’m prejudiced or anything. I just feel more comfortable doing the course if there’s at least something familiar in the environment.
Anyway, these steps are something I seem to need each time when starting a new course, so I’ll just leave them here.
(Courtesy of this forum author – Sebastian Stein.)

  1. Test SBT and download basic scala dependencies.
    Download the quickcheck assignment and extract it to some folder.
    In this folder, issue the following command on a command line:

    sbt test

    This will download a large set of core scala dependencies.
    Exit the command line again.

  2. Install sbt-idea plugin.
    The sbt-idea plugin allows generating IDEA project files from sbt. Note, this is a plugin for SBT, not for IDEA!
  3. Create a folder .sbt/plugins if it doesn’t exist already in your $HOME folder.
    In the plugins folder, create a file build.sbt.
    Add the following line to the file:

    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2")
  4. Generate project files.
    Go to the folder, where you extracted the quickcheck assignment.
    Open a command line.
    Run:

    sbt gen-idea

    After completion, close the command line.

  5. Install Scala and SBT plugin in IDEA.
    Start IDEA.
    On the start screen, click “Configure”.
    Now, click “Plugins”.
    Type “scala” in the search field.
    Select “SBT” and “Scala” plugins in the search results and install them.
    Restart IDEA.
    1. Advertisements

About Maryna Cherniavska

I have productively spent 10+ years in IT industry, designing, developing, building and deploying desktop and web applications, designing database structures and otherwise proving that females have a place among software developers. And this is a good place.
This entry was posted in IntelliJ and tagged , , , . Bookmark the permalink.

One Response to How to setup IntelliJ Idea for Scala SBT projects

  1. keramida says:

    Awesome post, thanks for writing this in one, concise place!

    I also found out recently that is helps to define an “SDK” for the IntelliJ project. This makes IntelliJ recognize syntactic constructs like “%d”.format(number) or similar. I am working on a Macbook right now, so I can describe how that worked for me, but I’m pretty sure it’s also possible in other OSes too:

    1. Open “File”, and navigate to “Project structure”
    2. Select “SDKs” on the left side, and then click on the “+” sign at the top of the dialog
    2.1. Navigate to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    2.2. Add the standard JDK 1.6 libraries to the new SDK
    3. Select “Project” in the left side, and use the drop-down menu of “Project SDK” in the right side to select the default SDK for the entire project
    4. Click “Apply” and finally
    5. Select “File” and then “Invalidate caches / Restart” to relaunch IDEA with fresh settings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s