IntelliJ IDEA 2024.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 displayed 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 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, refer to the Scala blog post.

Configure compilation settings

  1. Press Ctrl+Alt+S to open settings and then select Build, Execution, Deployment | Compiler | Scala Compiler.

  2. On the Scala Compiler page, choose the incremental compiler such as Zinc, which is 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
  3. Select Scala Compile Server under Scala Compiler to configure the Scala Compile Server.

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

    the Scala Compiler Server settings

Build process and compilation charts

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.

Big projects are often divided into modules. Each of those modules is compiled in phases, and a phase may contain many units (source files). While some modules can be compiled in parallel, others need to wait in sequence for yet other modules to be compiled first. Their order and relations are described in the build system configuration files, such as build.sbt for sbt. IntelliJ IDEA can read those files, and when you select Build | Build Project, it will use the information to generate a compilation chart. By default, the chart will only show modules that are being compiled. You can use the Level drop-down list to switch to Phases or Units to see the different level of details in the compilation process.

Delegate a Scala project build to sbt

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. Open the IDE settings and then select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions.

sbt settings: sbt projects section

Then, 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

To learn more, refer to SBT support.

Last modified: 11 February 2024