Getting Started with SBT
IntelliJ IDEA lets you create a new or import an existing project with a SBT module. SBT is a build tool for your Scala projects. You can also use SBT for Java projects.
- Before you start
- Creating a project
- Exploring the project structure
- Importing an SBT project
- Adding and refreshing a dependency in the SBT project
- Editing SBT project settings
Before you start
Before you start creating your SBT project, make sure that the Scala plugin is downloaded and enabled in IntelliJ IDEA.
Creating an SBT project
- If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select File | New | Project.
- In the left-hand pane, select Scala.
Note that for creating a Java project with an SBT module, you need to select Java.
- In the right-hand pane, select SBT.
You can also select Scala for creating a project with the Scala module, Play 2.x for creating a project with the Play 2.x framework Activator for creating a project with Typesafe Activator templates or Dotty for creating a project with the Dotty SDK. Click Next.
- On the next page of the wizard, specify project and module location settings. If the Scala SDK is not specified, click Create, select a necessary SDK version for downloading and click OK.
- Specify the following additional options for your project:
- Use auto-import - select this check box to resolve all the changes made to the SBT project automatically every time you refresh your project.
- Create directories for empty content roots automatically - select this option to add the src directory to your project.
- Download sources and docs - select this check box to download sources and docs for project dependencies.
- Download SBT sources and docs - select this check box to download sources docs for SBT itself.
Exploring project structure
IntelliJ IDEA creates the following SBT-specific directories:
- project directory - this directory contains build-related information such as configuration classes.
- target directory - this directory contains compiler-related information such as generated objects and classes and is excluded by default.
- build.sbt file - in this file you can add dependencies, plugins, etc.
IntelliJ IDEA also creates an SBT Tool window. You can use this window for adding tasks, refreshing your SBT projects, attaching or detaching external projects.
Importing an SBT project
IntelliJ IDEA lets you import an existing SBT project.
- On the main menu select .
- In the window that opens, select a file that you want to import and click OK. The Import project wizard opens.
- On the first page of the wizard, select Import project from external model option and choose SBT project from the list. Click Next.
- On the next page of the wizard, select SBT options and click Finish.
Adding and refreshing a dependency in SBT project
IntelliJ IDEA lets you add and refresh dependencies in your SBT project.
- Open the
build.sbtfile and add a dependency.
- If you chose the Use auto-import option when you imported your project than your dependency is imported automatically.
- If you didn't choose Use auto-import option then after you have added your dependency in the
build.sbtfile, press Refresh all SBT projects button in the SBT tool window to import the dependency. Note that you will also see the pop-up message suggesting to enable the auto-import option.
Editing SBT project settings
IntelliJ IDEA lets you edit its project's settings. This might be helpful if you, for example, didn't specify some options during the SBT project's import.
- On the main menu, select File |Settings ('Preferences' for OSX) | Build, Execution, Deployment | Build Tools | SBT.
The SBT page opens. Edit the settings and click OK.