Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT on IntelliJ takes a very long to time refresh

I have a fairly large project (15+ subprojects) which has a lot of external dependencies. When I change even a single line in build.sbt and then hit refresh, IntelliJ keeps on resolving various dependencies for a very long time (30+ minutes).

Is it supposed to be this slow? Using sbt from command line does not take more than 30 secs or so.

I am using -

Macbook pro mid 2015 with 16 GB ram
IntelliJ IDEA Ultimate 2017.2.5
sbt 0.13.13 
scala 2.11.11
like image 952
Kakaji Avatar asked Nov 24 '17 09:11

Kakaji


2 Answers

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.

like image 77
Haspemulator Avatar answered Sep 24 '22 20:09

Haspemulator


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

like image 40
fedeoasi Avatar answered Sep 23 '22 20:09

fedeoasi