SBT on IntelliJ takes a very long to time refresh

Viewed 10803

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
4 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.

I enabled SBT shell inside IntelliJ as suggested by @y.bedrov and now the refresh is as fast as command line!

Preferences > Build, Execution, Deployment > Build Tools > SBT > check "Use SBT shell for build and import".

I am using the combination of the 2 above ( - Preferences > Build, Execution, Deployment > Build Tools > SBT > check "Use SBT shell for build and import" - coursier

with the following global build.sbt :

    // file: ~/.sbt/0.13/plugins/build.sbt
    // purpose: add jar utils useful for development, but not wanted to projects' build.sbt

    // much better depts resolvement and fetching
    // usage: sbt update
    // https://github.com/coursier/coursier#why
    resolvers += Resolver.sonatypeRepo("snapshots")
    addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-SNAPSHOT")


    // enable this one if you want to use the local artifacts in your local repo's
    // ~/.ivy2/local/
    // ~/.ivy2/cache/
    // instead of the remote ones
    // updateOptions := updateOptions.value.withLatestSnapshots(false)


    resolvers ++= Seq(
       "typesafe" at "https://dl.bintray.com/typesafe/ivy-releases/",
       "Maven External Releases" at "https://artifactory-espoo1.ext.net.nokia.com/artifactory/public-maven-remotes/"
    )


    // eof file: ~/.sbt/0.13/plugins/build.sbt
Related