Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon

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.

1. Create a New Project

Let’s create a new project from scratch. To do that, chooseFileNew Projecton the main menu, or click the New Project icon on the Welcome screen. On the first page of the New Project wizard, in the selector pane, choose SBT. On the right part of the page, enter the necessary information, such as project's name, its location and click Finish:

 

2. View Project Tool Window


Intellij IDEA creates the following SBT-specific directories:

  • target directory - this directory contains compiler-related information such as generated objects and classes.
  • build.sbt file - in this file you can add dependencies, plugins, etc.
  • SBT build directory - this directory contains build-related information such as configuration classes.

3. View SBT Tool Window

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.

4. Import SBT Project


IntelliJ IDEA lets you import an existing SBT project.
To import an existing project, on the main menu selectFile→ Import Project. 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 the following options:

  • 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 a src directory to your project. When you import a project the scr directory is not created. When you create a project, the src directory is generated automatically.

    Click Finish.

5. Add a Dependency to an SBT Project

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

To do that, open the build.sbt file 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 that 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.


You will also see the pop-up message suggesting to enable the auto-import option.


6. Edit SBT Project Settings

IntelliJ IDEA lets you edit the project's settings. This might be helpful if you, for example, didn't specify some options during the project's import.
To edit your project's settings, on the main menu selectFile →Settings→ Project Settings→ SBT.
The SBT page opens. Edit the settings and click OK.

  • No labels

11 Comments

  1. Anonymous

    There is no File > Settings menu item.  Doesn't exist.

    1. Anonymous

      You are not using IntellijIDEA I guess

      1. Anonymous

        Cool down man ;)

    2. Anonymous

      For Mac OS, it's IntelliJ IDEA -> Preferences...

  2. Anonymous

    Does IDEA able to create and manage an multi-module SBT project? 

    1. Anonymous

      Great question!

  3. Anonymous

    OK, so I created an SBT project. How do I start writing code? I see no command to create a main class.

    1. Anonymous

      Some guy has a video tutorial: https://www.youtube.com/watch?v=TBuX5HtDoT8

      I was only able to add code after doing File > Invalidate Caches / Restart.

  4. Anonymous

    There is a typo at the sentence 

    When you import a project the scr directory 

    It should be 

    When you import a project the src directory 

    - Ramon Buckland

  5. Anonymous

    On Intellij IDEA Ultimate 14.1.4, there is no src directory tree structure. I have to create them manually. SBT should normally create these folders automatically. I even checked the box labeld "Create directories for empty content automatically" and still it doesn't work.

  6. Anonymous

    I found a bug that import from SBT will invalidate previous configured Scala SDK. I am using IDEA 14.1.2