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, chooseFile→New 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.
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.