How to synchronize Intellij and sbt builds for a scala project

Viewed 2868

I have an sbt project that I have imported into Intellij. Sometimes I build the project at the command line using sbt, and then when I need to debug I build it from within Intellij. However, each time I alternate it requires a full rebuild when there is no need. Both build procedures output to the same class folder, namely .../target/scala-2.11/classes, so I don't understand why a full rebuild keeps happening?

2 Answers

As stated by CrazyCoder, intellij and sbt build have each their own tracking of changed files for incremental build. Thus each time one re-compile a file, the other treats it as a changed file and recompile it too.

While CrazyCoder's answer describes how to make them work on separated directory, by changing the sbt compiled classes dir. This answer explain how you can configure Intellij to use sbt for all build, thus only sbt does the compilation. This is a relatively new feature.

Just check the option:

file
  > Settings
    > Build, Execution, Deployment
      > Build Tools
        > SBT 
          > Use SBT shell for build and import

It works at least since intellij version 2017.2.3, and most probably it is an option from the SBT plugin.

For details about this feature, see jetbrains ticket: https://youtrack.jetbrains.com/issue/SCL-10984

Related