Project configuration explained

Pavel Fatin

Although the work on new Scala project configuration is still in progress, a brief clarification may come in handy.

  • A module that requires compiling with Scalac should have a Scala facet attached.
  • Facet refers to “Compiler library” which is used to instantiate Scalac inside JVM (the library provides “compiler classpath” that is completely separated from “project classpath”)
    Compiler library (usually) should include scala-compiler*.jar and scala-library*.jar.
    For special purposes, compiler library may include directories (like “/build/classes/”, etc), in that case, no library validation is performed.
  • Facet holds custom compiler options and a list of Scalac plugins (relative paths allowed).
  • As usual, modules that use Scala standard library should include it in module dependencies.
  • Both compiler library and standard library may be created using build-in wizard (from Scala distribution).
  • Plugins doesn’t include bundled Scalac anymore.
  • Maven projects can be imported automatically.

To create a new project that uses Scala:

  1. In “New Project” wizard check “Scala” in technologies list.
  2. Provide a path to Scala installation (if not detected)

To add a new module that uses Scala into existing project:

  1. In “Add Module” wizard check “Scala” in technologies list.
  2. Provide a path to Scala installation (if not detected)

To add Scala support to existing module:

  1. Right-click the module in Project View, choose “Add Framework Support…”
  2. Check “Scala” in technologies list (unavailable if module has Scala facet attached)
  3. Provide a path to Scala installation (if not detected)

To manually configure existing module:

  1. Create library “scala-compiler”:
    Classes: scala-compiler.jar; scala-library.jar
  2. Create library “scala-library”:
    Classes: scala-dbc.jar; scala-library.jar; scala-swing.jar
    Sources: scala-dbc-src.jar; library-src.jar; swing-src.jar
    Docs: /doc/scala-devel-docs/api/
    (if you downloaded Scala as an archive, you need to get separate API docs archive and extract it so that <scala home>\doc\scala-devel-docs\api exist; if you installed Scala using LzPack, then API docs are already there)
  3. Add Scala facet to the module, select “scala-compiler” library as compiler library
  4. Add “scala-library” to module dependencies.

Hints:

  • Don’t add Scala compiler library to module dependencies (unless you really need Scala compiler classes in your code)
  • Don’t forget to attach “scala-library*.jar” to Scala compiler library, it’s a dependency of “scala-compiler*.jar” itself.

Screenshots

Scala support for existing module:

Wizard (on new project, on new module, after “Add Framework Support…”):

Libraries:

Standard library:

Compiler library:

Module dependencies:

Facet settings:

Advanced facet settings:

Autocompletion (Scala standard library):

Documentation lookup (Scala standard library API docs):

Definition lookup (Scala standard library sources):

Comments below can no longer be edited.

8 Responses to Project configuration explained

  1. Alain O'Dea says:

    April 27, 2011

    The Maven import is easily the best way to get a project started for the Scala Plugin IMHO.

    For those not using Maven, this is useful. I followed these directions and successfully got an existing large-scale multi-module Java project to work with the plugin.

    The project settings are also portable, which makes team development much easier. Kudos 🙂

  2. Adrian says:

    November 21, 2011

    Extremely useful. Thanks.

  3. Moritz says:

    February 5, 2012

    Thanks for the writeup! Very helpful! The manual configuration/creation of the scala-compiler library was not that intuitive

  4. melgart says:

    June 5, 2012

    these directions are still good for getting Intellij 10.5 and scala 2.9.2 working. thank you OP.

  5. Vlad Patryshev says:

    February 19, 2013

    what am I doing wrong?
    I have scala-compiler.jar, scala-library.jar in one library, but the compiler does not see it

    intellij 123.123

  6. Arsalan says:

    December 10, 2014

    Thanks for this article. I was really searching for this thing.

  7. facebook covers says:

    February 23, 2020

    It’s awesome to visit this site and reading the views of all colleagues regarding this article, while I am also zealous of getting know-how.