IntelliJ IDEA 2021.1 Help

Compile and build Scala projects

By default, Scala projects are built with the Scala compiler and IntelliJ IDEA. The output of the compilation process is dislpayed in the Build tool window. You can also delegate the build actions to sbt. In this case, the output of your build is displayed in the sbt shell.

Scala compilation settings

By default, you use the Scala compiler(scalac) to compile your Scala project. Besides the Scala compiler that supports incremental compilation, you can use the Scala Compile server, which is a Scala compilation subsystem. It helps you reduce the compilation overhead and with the supported parallel compilation can significantly speed up your compilation process. For more information, see the Scala blog post.

Configure compilation settings

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment |Compiler |Scala Compiler.

    On the Scala Compiler page, you can choose the incremental compiler such as Zinc, which a standalone version of the incremental compiler or the IntelliJ IDEA native one. You can also select the compilation order in which code should be compiled. For example, compile first Scala code and then Java code.

    the Scala Compiler settings
  2. Select Scala Compile Server under Scala Compiler to configure the Scala Compile Server.

  3. On the Scala Compile Server page, you can configure the parallel compilation options and the JVM settings.

    the Scala Compiler Server settings

Scala project build process

When you build(Ctrl+F9) a Scala project, the compilation is done with the Scala server. The output of the compilation is displayed in the Build tool window. Besides the regular compilation output, IntelliJ IDEA displays a chart which can help you optimize the structure of your project modules and the VM options of the Scala Compile Server.

Build Scala project

  1. From the main menu, select Build | Build Project (Icons actions compile Ctrl+F9 ).

  2. Check the output and the chart in the Build tool window (Build Output tab).
    the Build tool window: Compilation chart

    The compiler work is done in phases, and a phase may contain many units (source files). You can use the Level list to see how those are processed during the compilation. You can switch to Phases or Units to see the different level of details in compilation process.

sbt builds

You can delegate a build of your project to sbt. In this case, such steps as compilation and source generation are run within sbt, making the process closer to the actual CI build. The build is executed through the sbt shell where you can view the output.

Delegate a Scala project build to sbt

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment |Build Tools |sbt.

  2. In the sbt projects section, select a project for which you want to configure build actions.

    sbt settings: sbt projects section

  3. In the sbt shell section, select the builds option. Click OK to save the changes.

    Now when you build your project (Ctrl+F9 ), the build is run in the sbt shell.

    sbt shell
Last modified: 07 April 2021