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
Press Ctrl+Alt+S to open IDE settings and select 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.
Select
under to configure the Scala Compile Server.On the Scala Compile Server page, you can configure the parallel compilation options and the JVM 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
From the main menu, select
( Ctrl+F9 ).- Check the output and the chart in the Build tool window (Build Output tab).
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
Press Ctrl+Alt+S to open IDE settings and select Build, Execution, Deployment | Build Tools | sbt.
In the sbt projects section, select a project for which you want to configure build actions.
- 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.