31
votes

I imported an SBT project into into Intellij 13.1.

Whenever I change build.sbt, plugins.sbt, etc., Intellij reruns SBT.

Sometime that is nice, but when I do lot of stuff in the console, and after frequent changes, I have to wait because my IDE locks SBT from running (and SBT is sloooow).

Anyway, can I turn off the automatic SBT run in Intellij. I would prefer to do it myself, from the provided SBT window.

6

6 Answers

25
votes

I would leave the autoimport checkbox unchecked when importing a SBT project.

In this way, it doesn't refresh automatically, it must be done by hand.

In order to change it, after it has been imported, you can edit by hand the .idea/sbt.xml file:

<project version="4">
  <component name="ScalaSbtSettings">
    <option name="linkedExternalProjectsSettings">
      <SbtProjectSettings>
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="jdk" value="1.7" />
        <option name="resolveClassifiers" value="true" />
        <option name="useAutoImport" value="true" />
      </SbtProjectSettings>
    </option>
  </component>
</project>

and change the useAutoImport setting. If necessary, restart IDEA.

UPDATE: Also in the settings page, search for SBT, and there you can enable or disable auto-import of SBT files.

When doing heavy work on a .sbt file, I disable auto-import.

20
votes

IntelliJ 14.1 now allows you to adjust SBT settings after importing projects.

File > Settings > Build > Build Tools > SBT (Or click the settings button on the SBT projects panel.)

Uncheck "auto-import".

enter image description here

This is the user-friendly equivalent of david.perez's answer.

18
votes

In IntelliJ 2017.1 and later, you open the SBT projects window on the right sidebar, right-click on the project name, and uncheck the Auto-import option

1
votes

In Community 2020.2 (on MacOS, but it probably doesn't change), the path is Settings > Build, Execution, Deployment > Build Tools > Reload project after changes in build scripts. Sadly, it appears to only be settable for the current project, not globally.

Intellij IDEA 2020.2 Build Tools Settings Window

0
votes

This doesn't completely solve it, but I've found that removing all target/ directories from the IntelliJ project helps a lot and greatly reduces waiting on Ivy locks.

For all target/ directories, right click, Mark Directory As, Excluded. If you're using sbt sub-projects, you'll have multiple of these (otherwise, just one).

Source: https://twitter.com/andstuff/status/516987670170697728

Related issue: How to stop auto-refreshing of SBT modules upon opening project in IDEA?, suggests upgrading to IDEA 14 Preview releases.

0
votes

None of the previous answers have clear instructions for Mac.

On Mac the workflow is IntellJ IDEA > Preferences > Build, Execution, Deployment > Build Tools > SBT > Use Auto-Import

Mac Version 16 SBT