SBT on IntelliJ takes a very long to time refresh

10,280

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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
Share:
10,280

Related videos on Youtube

Kakaji
Author by

Kakaji

Updated on September 15, 2022

Comments

  • Kakaji
    Kakaji over 1 year

    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
    
    • y.bedrov
      y.bedrov over 6 years
      Do you have "Download sbt sources" option disabled? Also you could try to enable "Use SBT shell for build and import" option.