SBT on IntelliJ takes a very long to time refresh

Kakaji and Haspemulator's answers helped me take the import down to ~3 minutes on a ~40 project build. In addition to that I found out that most of the time in the IntelliJ SBT import was spent fetching the dependencies from Ivy as part of the updateClassifiers command.

This happens every time you perform the import if you have the 'Library Sources' checkbox enabled when you import the project. I would expect it to be slower if you also check 'sbt sources' because that means more libraries to resolve.

One way to speed up updateClassifiers is to use coursier for dependency resolution. I just added the following line to project/plugins.sbt and now it imports in ~1 minute.

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.1")

You can read more about updateClassifiers being slow at https://github.com/sbt/sbt/issues/1930


One thing can help is cached dependency resolution, which is a setting available starting from sbt 0.13.7. Have a look here: http://www.scala-sbt.org/1.0/docs/Cached-Resolution.html, but basically you need to enable the following setting for all of the projects in your build:

updateOptions := updateOptions.value.withCachedResolution(true)

I was able to cut down IntelliJ project refresh time from 15 minutes to 3 minutes with this setting. Still not ideal, but way more manageable.

There are some caveats, since it's an experimental setting, they're described in that page. Basically, if you have SNAPSHOT dependencies, enabling this will only make things worse, so be conscious of that.