Importing an sbt project into Intellij

§Importing an sbt project into IntelliJ

Before importing, configure IntelliJ IDEA to use the most recent Scala plugin, which includes sbt support (Use this plugin regardless of whether you are using the Java or the Scala API).

Note The instructions on this page were verified with IntelliJ IDEA Community Version 2016.3.4. The procedures and screens can differ depending on the version, but the basic flow should be the same.

The following sections provide detailed steps for configuring IDEA and importing an sbt project.

§Add the Scala plugin

A number of Scala plugins are available. We recommend the plugin provided by JetBrains:

To verify or add the JetBrains Scala plugin, follow these steps:

  1. Open the Settings dialog:
    • If you have a project open, from the File menu, select Settings.
    • Otherwise, from the Welcome page Configure menu, select Settings.
      The Settings (or Plugins) dialog will open. If you open the Settings, select Plugins.
  2. In the search box, enter Scala.
    • If you have it installed, you will see an option to uninstall it.
    • If you do not have it installed and it does not show in the list, click Browse repositories…. Scroll to find the appropriate plugin and click Install.
      The dialog prompts you to restart IDEA.

Now you are ready to import your project.

§Import an sbt project

After you have an sbt build – one you created yourself or from a template – follow these steps to import the project into IntelliJ IDEA:

  1. From the Welcome Screen or File menu, select Open.
  2. Browse to and select the top-level folder of your sbt project, and click OK.
    The Import Project from SBT dialog opens.
  3. For import options:

    1. Enable use auto-import.
    2. For Download options, enable Sources and disable Javadocs and Sources for SBT and plugins.
    3. For Project SDK, verify the version (JDK 1.8).
    4. Leave Project format: at the default, .idea (directory based). The screen should look something like this:
    5. Click OK.
      The first time you import an sbt project, the SBT Project Data To Import screen opens and asks you to confirm the import. IDEA opens the project. The status bar shows sbt downloading dependencies and refreshing the project:
  4. You can build and run the project from the Terminal or create a Run Configuration as follows:
    1. From the Run menu, select Run.
    2. Click Edit Configurations….
    3. Click + (Add New Configuration).
    4. Select SBT Task.
    5. Name your configuration.
    6. In the Tasks field, enter runAll.
    7. Click Run.
      A Run tab opens and you should see messages from the build, with the services starting up at the end:
    8. Verify that the services are indeed up and running by invoking the hello service endpoint from any HTTP client, such as a browser:

      The request returns the message Hello, World!.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.