IntelliJ IDEA 2016.2 Help

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

Before you start creating your SBT project, make sure that the Scala plugin is downloaded and enabled in IntelliJ IDEA.

Creating an SBT project

  1. If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select File | New | Project.

    As a result, the New Project wizard opens.

  2. In the left-hand pane, select Scala.
    Note that for creating a Java project with an SBT module, you need to select Java.
  3. 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.
  4. 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.
  5. 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.
    Click Finish.

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.

  1. On the main menu select File | New | Project from Existing Sources.
  2. In the window that opens, select a file that you want to import and click OK. The Import project wizard opens.
  3. On the first page of the wizard, select Import project from external model option and choose SBT project from the list. Click Next.
  4. On the next page of the wizard, select SBT options and click Finish.

If you import a multi-module project, IntelliJ IDEA opens the SBT Project Data to Import dialog where you can select modules that you want to include in your project.


Adding and refreshing a dependency in SBT project

IntelliJ IDEA lets you add and refresh dependencies in your SBT project.

  1. Open the build.sbt file and add a dependency.
  2. If you chose the Use auto-import option when you imported your project than your dependency is imported automatically.
  3. If you didn't choose Use auto-import option then after you have added your dependency in the build.sbt file, 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.
Last modified: 23 November 2016