22 Replies Last post: Sep 2, 2010 6:47 PM by Alain O'Dea  
Pavel Fatin JetBrains 274 posts since
Nov 12, 2009
Currently Being Moderated

Aug 16, 2010 3:56 PM

Project configuration explained

Although the work on new Scala project configuration is still in progress, here's a brief clarification.

 

  • 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.

 

Mini HOWTOs:

 

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
    • 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)
      • Add Scala facet to the module, select "scala-compiler" library as compiler library
      • 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)
      • Remember to attach "scala-library*.jar" to Scala compiler library, it's a dependency of "scala-compiler*.jar" itself.

       

      Comments and suggestions welcome.

       

       

      Screenshots

       

      Scala support for existing module:

      framework.png

       

      Wizard (on new project, on new module, after "Add Framework Support..."):

      support.png

       

      Libraries:

      libraries.png

       

      Standard library:

      standard.png

       

      Compiler library:

      compiler.png

       

      Module dependencies:

      dependencies.png

       

      Facet settings:

      facet.png

       

      Advanced facet settings:

      settings.png

       

      Autocompletion (Scala standard library):

      completion.png

       

      Documentation lookup (Scala standard library API docs):

      docs.png

       

      Definition lookup (Scala standard library sources):

      implementation.png

      Lukas Rytz Newbie 14 posts since
      Apr 9, 2010
      Currently Being Moderated
      Aug 6, 2010 12:55 PM in response to: Pavel Fatin
      Re: Project configuration explained

      Hi Pavel,

       

      many thanks, the new facet configuration is much more intuitive and user-friendly. I only have the following issue when using it for the scala compiler:

       

      The facet configuration only accepts libraries which contain a "scala-compiler*.jar". Providing a library that contains a classfile directory ("build/locker/classes/compiler") does not work. The same is probably true for "scala-library*.jar". For the compiler module, i'd like to link a library which contains ("build/locker/classes/compiler", "build/locker/classes/library", "lib/fjbg.jar", "lib/msil.jar").

       

      Thanks: Lukas

      Lukas Rytz Newbie 14 posts since
      Apr 9, 2010
      Currently Being Moderated
      Aug 6, 2010 2:30 PM in response to: Pavel Fatin
      Re: Project configuration explained

      i understand.. it could be a warning in the facet configuration, but not an error when trying to compile.

      many thanks: lukas

      Barry Kaplan Novice 320 posts since
      Sep 28, 2006
      Currently Being Moderated
      Aug 6, 2010 8:51 PM in response to: Pavel Fatin
      Re: Project configuration explained

      What needs to be done for existing maven projects. I just jumped versions from the no-facets to the new facets. Before the scala compiler was picked up via the maven dependency. Now it is not. Force Reimport has no effect.

       

      Will I now have to manually manage/sync the compiler version specified in maven with the facet?

       

      Hmm, actually now I'm getting corruption. See attached screen shot. No errors in the log and not thread dumps. I'm wondering if this corruption is maven related. Its similar to SCL-2088).

       

      -barry

      Attachments:
      Taras Tielkes Apprentice 1,029 posts since
      Oct 20, 2002
      Currently Being Moderated
      Aug 8, 2010 12:43 AM in response to: Pavel Fatin
      Re: Project configuration explained

      I have a single-module project that contains the following Maven dependencies:

       

       

      ...

              <dependency>

                  <groupId>org.scala-lang</groupId>

                  <artifactId>scala-library</artifactId>

                  <version>2.8.0</version>

              </dependency>

              <dependency>
                  <groupId>org.scala-lang</groupId>
                  <artifactId>scala-compiler</artifactId>
                  <version>2.8.0</version>
                  <scope>compile</scope>
              </dependency>
      ...

       

       

      When I attempt to run a Scala object main method from this module, I get the nice message box "Please, adjust compiler library in Scala facet: no scala-library*.jar found".

      The facet configuration allows me to pick a compiler library only. Where in the facet config am I supposed to configure a library library?

       

      More to the point, since all the required elements are already in my Maven pom.xml, why am I forced to mess with facet settings and such?

       

      -tt (using plugin version #0.3.1979)

      Alain O'Dea Newbie 9 posts since
      Mar 21, 2003
      Currently Being Moderated
      Sep 2, 2010 6:47 PM in response to: Pavel Fatin
      Re: Project configuration explained

      I elaborate Maven configuration further in the case of a mixed Scala/Java project on StackOverflow:

      http://stackoverflow.com/questions/3628132/auto-configure-scala-facet-in-intellij-idea-for-mixed-scala-java-maven-project/3628261#3628261

      Ittay Dror Newbie 27 posts since
      Nov 15, 2009
      Currently Being Moderated
      Aug 8, 2010 12:38 PM in response to: Pavel Fatin
      Re: Project configuration explained

      How do I run the wizard that creates the Scala Compiler library?

      Ittay Dror Newbie 27 posts since
      Nov 15, 2009
      Currently Being Moderated
      Aug 8, 2010 2:05 PM in response to: Pavel Fatin
      Re: Project configuration explained

      If I reimport the modules from Maven, it creates per module an empty library named 'maven: org.scala-lang:scala-compiler:2.8.0.RC6'. Since it is empty, I get errors that no scala-library*.jar . Because import happens automatically, even if I configure my own 'Scala SDK' global library and attach it to all modules (one by one, a long and slow process), it is detached and the empty library is set instead.

      Ittay Dror Newbie 27 posts since
      Nov 15, 2009
      Currently Being Moderated
      Aug 8, 2010 6:10 PM in response to: Pavel Fatin
      Re: Project configuration explained

      Why must there be a configuration per module? Isn't it easier to have to set it once in the general settings and override per-need in the module?

      Ittay Dror Newbie 27 posts since
      Nov 15, 2009
      Currently Being Moderated
      Aug 11, 2010 3:17 PM in response to: Pavel Fatin
      Re: Project configuration explained

      how do i set project-local settings for scala? (i tread the scala facets as module-local)

      Ittay Dror Newbie 27 posts since
      Nov 15, 2009
      Currently Being Moderated
      Aug 11, 2010 3:41 PM in response to: Pavel Fatin
      Re: Project configuration explained

      if i do this,how do i prevent the setting in the scala facet from taking precedence?

      Mike Carifio Newbie 33 posts since
      Jul 24, 2008
      Currently Being Moderated
      Aug 12, 2010 6:33 PM in response to: Pavel Fatin
      Re: Project configuration explained

      If I attached the javadoc, should I see text descriptions for various scala builtin when I use completion (ctrl-space)?

      Not seeing it currently and would like to.

       

      Build 1814 is an improvement. Thank you.

      Mike Carifio Newbie 33 posts since
      Jul 24, 2008
      Currently Being Moderated
      Aug 16, 2010 6:02 PM in response to: Pavel Fatin
      Re: Project configuration explained

      Pilot error on my part. Works fine, thanks.

      More Like This

      • Retrieving data ...