Open an existing sbt project
If no project is currently opened in IntelliJ IDEA, click Open on the welcome screen. Otherwise, select from the main menu.
In the dialog that opens, select a file that contains your sbt project description build.sbt. Click OK.
In the dialog that opens, click Select as Project.
IntelliJ IDEA opens and syncs the sbt project in the IDE. If you need to adjust importing options when you open the project, refer to the sbt settings.
Ensure sbt and Scala versions compatibility
Often you share your project across a team and need to use a specific version of sbt. You can override the sbt version in your project's build.properties file.
Create or open your sbt project.
In the Project tool window, in the source root directory, locate the build.properties file and open it in the editor.
In the editor explicitly specify the version of sbt that you want to use in the project.sbt.version=xxx
Reimport your project. (Click the in the sbt tool window.)
sbt project structure
When you create or import the sbt project, IntelliJ IDEA generates the following sbt structure:
sbt project (proper build) which defines a project and contains build.sbt file, src, and target directories, modules; anything related to a regular project.
sbt build project which is defined in the project subdirectory. It contains additional code that is part of the build definition.
the sbt tool window which contains sbt tasks, commands, and settings that you can execute.
Manage sbt projects
When you work with sbt projects you use the build.sbt file to make main changes to your project since IntelliJ IDEA considers the sbt configuration as a single source of truth.
Every time you manually change build.sbt in the editor, you need to load the changes. IntelliJ IDEA displays a nofication icon in the right part of the editor suggesting to Load sbt Changes made to the project (Ctrl+Shift+O).
If you want to control the importing process of your project, you can manually trigger the action or configure the auto-reloading process.
Reload an sbt project
In the sbt tool window, right-click a linked project.
From the context menu, select Reload project .
On invoking this action, IntelliJ IDEA parses the project structure in the sbt tool window.
IntelliJ IDEA cannot reload just a part of your project, it reloads the whole project including subprojects and dependencies.
Configure the auto-reload
In the Settings/Preferences dialog (Ctrl+Alt+S), go to .
Alternatively, In the sbt tool window, click and select the Auto-Reload Settings option.
In the Build tools settings, specify the following options:
Reload changes in the build scripts: this option is selected by default. If you want to disable the auto-reload and manually control the reloading process, unselect this checkbox.
Any changes: select this option if you want to automatically reload the project after any changes you make to build.sbt or external changes.
Every time you manually change the sbt build script in the editor, you need to load the changes. IntelliJ IDEA displays a nofication icon in the right part of the editor suggesting to Load sbt Changes made to the project (Ctrl+Shift+O).
With the Any changes option, IntelliJ IDEA reloads all the changes automatically.
External chages: when you select this option, IntelliJ IDEA automatically reloads the project only after the VCS changes and changes made to the build files outside the IDE.
Link an external sbt project
Open your build.sbt.
Specify the following code:val localDep = RootProject(file("/path/to/project"))
localDepin this case is a project that is located somewhere on the file system and will be imported as a module.
Reload your project. (Click the in the sbt tool window.)
IntelliJ IDEA displays the added project in the Project tool window as well as in the sbt tool window.
Add a sub-project or a module to the sbt project
Open build.sbt in the editor.
Specify, for example:lazy val sampleModule = (project in file("sampleModule"))
"sampleModule"in this case is a sub-project that you want to add. You can specify more than one sub-project.
Reimport your project. (Click the in the sbt tool window.)
IntelliJ IDEA generates a sub-project directory with the appropriate information and displays it in both Project and sbt tool windows.
If you want the sub-projects to automatically update when you change the version of Scala, specify
settings method call for each sub-project.
Specify, for example, the following code:lazy val commonSettings = Seq( organization := "com.example", version := "0.1.0-SNAPSHOT", scalaVersion := "2.12.6" ) lazy val moduleSample = (project in file("moduleSample")) .settings( commonSettings )
The appropriate Scala version is added to the sub-project's directory in the Project tool window and to the sbt tool window as a dependency in the sub-project.
Add a library to the sbt project
You can add sbt dependencies via the build.sbt file or you can use the
import statement in your .scala file.
Open a .scala file in the editor.
Specify a library you want to import.
Put the caret at the unresolved package and press Alt+Enter.
From the list of available intention actions, select Add sbt dependency.
Follow the steps suggested in the wizard that opens and click Finish.
IntelliJ IDEA downloads the artifact, adds the dependency to the build.sbt file and to the sbt tool window.
Work with sbt shell
An sbt shell is embedded in the sbt project and is available on your project start. You can use the sbt shell for executing sbt commands and tasks, for running, and debugging your projects.
To start the sbt shell, press Ctrl+Shift+S(for Windows) or ⌘+⇧+S (for Mac OS X). Alternatively, click on the toolbar located at the bottom of the screen.
To use the sbt shell for build and import procedures, select the Use sbt shell section located in the sbt settings and perform steps described in the Run a Scala application using the sbt shell section.
To use the sbt shell for debugging, refer to the debugging with sbt shell section.
To run your tests from the sbt shell:
Open a run/debug configuration ().
Create a test configuration and select the use sbt option from the available settings.
Run sbt tasks
You can run sbt tasks by selecting the one you need from the sbt Tasks directory in the sbt tool window.
You can manually enter your task (code completion is supported) in the sbt shell and run it directly from there.
You can create a run configuration for a task. For example, you can create a custom task which is not part of the list of tasks located in the sbt tool window.
Press Alt+Shift+F10 to open a run configuration.
Specify the run configuration settings and click OK. If you need, you can add another configuration or a task to execute before running your configuration. Click in the Before Launch section and from the list that opens, select what you need to execute.
When you work in the distraction-free mode (without toolbars and tool windows), you can run sbt tasks or commands from the Run Anything window. Press Ctrl twice to open it, type your command and press Enter.
IntelliJ IDEA displays results in the sbt shell window.
Work with sbt settings
Use the sbt settings to configure the build and run actions the sbt project, an sbt version, importing of the project's changes, and so on.
Access the sbt settings
Press Ctrl+Alt+S to open the IDE settings and select.
Alternatively, click on the toolbar of the sbt tool window to access the sbt settings.
On the sbt settings page, configure the following notable actions:
To delegate running builds to sbt, next to Use sbt shell, select the for imports and for builds options.
To debug your code via the sbt shell, select Enable debugging for sbt shell option that enables the debug button in the sbt shell tool window.
For more information on debugging, see debugging with sbt.
To change the .ivy cache location in your project or set other sbt properties, use the VM parameters field.
Click OK to save the changes.
To check the most common sbt issues and workarounds, see the sbt troubleshooting section.