Setting up Scala in IntelliJ 11

Having just gone through the process of setting up Scala for use in IntelliJ, I thought it would be helpful to share the experience so that others find an easier route.

Environment

Mac OS X 10.8
JDK 1.7 (Oracle download)

Download Scala Plugin

IntelliJ > Preferences > Plugins > Browse Repositories... > Scala
Click Ok and allow IntelliJ to restart

Download Scala

In Terminal enter
brew install scala
Setup symbolic links for IntelliJ discovery process
ln -s /usr/local/Cellar/scala/2.9.2/libexec/src /usr/local/Cellar/scala/2.9.2/src
ln -s /usr/local/Cellar/scala/2.9.2/libexec/lib /usr/local/Cellar/scala/2.9.2/lib

Download Scala Documentation

Make directories in Scala home
mkdir -p /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api

Download and Copy Manually

Unzip files from http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip



Copy contents of zip file to new directory
cp -r <path to unpacked zip root> /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api

or Download and Copy by Script

curl http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip -o scala-docs.zip; unzip scala-docs.zip; cp -r scala-docs-2.9.2/* /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api; rm scala-docs.zip; rm -rf scala-docs-2.9.2

Create Project in IntelliJ

Here you are going to create a Java project from scratch as you normally would.  However, in the last step, you will select Scala in the "Technologies" page.  

In the Standard Distribution enter /usr/local/Cellar/scala/2.9.2 

In the Compiler dropdown select scala-compiler

Click Ok and you are ready to create your first Scala object


Sidebar on IntelliJ/Scala Configuration

Scala and IntelliJ Facets

IntelliJ treats Scala as a Facet.  If you are not familiar with Facets, these are add-on features/technologies to the base project.  In IntelliJ, the base project is Java and Scala is Facet of that project.  Therefore, if you need to modify Scala's configuration for your project, you will find that this under Module Settings > Facets.

Module Dependencies

When you add the Scala Facet, IntelliJ should add the scala-library as a dependency for your module.  That is, when you Scala installs two parts both contained in the /usr/local/Cellar/scala/2.9.2/libexec/lib directory: a compiler; and the runtime library.  

In some case, IntelliJ does not add the scala-library as a dependency and therefore you will get compiler errors.  In order to rectify this, simply manually add scala-library to your module dependencies.



  1. Using the FSC Compiler

    If you are using the default project settings for your Scala-fied project, you may notice that every compile seems to process the entire project scope.  The FSC integration with IntelliJ appears to selectively compile only those classes that have changed.  Or at least, subsequent compilations are significantly faster than the first.

    Once you have this setup correctly, you will a) get occasional notifications from the FSC "server" and b) you will see the server status icon in the bottom edge of the window.


    FSC Status/Control










    Setting up FSC Compiler

    In your Project Settings (Command + ;)

    Select "Facets"

    Select the existing Scala Facet

    Select "Use project FSC"  

    Click ">> Settings"











    Ensure that the Scala Compiler is appropriately (e.g. Scala Compiler 2.9.2)  

    For this instance select "Run internal Server" (with default settings)

    Click "OK"

    Now you will see should the compiler server status in the lower window and your compile times reduce significantly
    0

    Add a comment

  2. Setting up Scala in IntelliJ 11

    Having just gone through the process of setting up Scala for use in IntelliJ, I thought it would be helpful to share the experience so that others find an easier route.

    Environment

    Mac OS X 10.8
    JDK 1.7 (Oracle download)

    Download Scala Plugin

    IntelliJ > Preferences > Plugins > Browse Repositories... > Scala
    Click Ok and allow IntelliJ to restart

    Download Scala

    In Terminal enter
    brew install scala
    Setup symbolic links for IntelliJ discovery process
    ln -s /usr/local/Cellar/scala/2.9.2/libexec/src /usr/local/Cellar/scala/2.9.2/src
    ln -s /usr/local/Cellar/scala/2.9.2/libexec/lib /usr/local/Cellar/scala/2.9.2/lib

    Download Scala Documentation

    Make directories in Scala home
    mkdir -p /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api

    Download and Copy Manually

    Unzip files from http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip



    Copy contents of zip file to new directory
    cp -r <path to unpacked zip root> /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api

    or Download and Copy by Script

    curl http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip -o scala-docs.zip; unzip scala-docs.zip; cp -r scala-docs-2.9.2/* /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api; rm scala-docs.zip; rm -rf scala-docs-2.9.2

    Create Project in IntelliJ

    Here you are going to create a Java project from scratch as you normally would.  However, in the last step, you will select Scala in the "Technologies" page.  

    In the Standard Distribution enter /usr/local/Cellar/scala/2.9.2 

    In the Compiler dropdown select scala-compiler

    Click Ok and you are ready to create your first Scala object


    Sidebar on IntelliJ/Scala Configuration

    Scala and IntelliJ Facets

    IntelliJ treats Scala as a Facet.  If you are not familiar with Facets, these are add-on features/technologies to the base project.  In IntelliJ, the base project is Java and Scala is Facet of that project.  Therefore, if you need to modify Scala's configuration for your project, you will find that this under Module Settings > Facets.

    Module Dependencies

    When you add the Scala Facet, IntelliJ should add the scala-library as a dependency for your module.  That is, when you Scala installs two parts both contained in the /usr/local/Cellar/scala/2.9.2/libexec/lib directory: a compiler; and the runtime library.  

    In some case, IntelliJ does not add the scala-library as a dependency and therefore you will get compiler errors.  In order to rectify this, simply manually add scala-library to your module dependencies.



Loading