Reputation: 25825
When using SBT with IntelliJ IDEA, often the project will get in to a bad state where compiler errors occur where they shouldn’t, when they don’t occur in the terminal.
A project will sbt compile
in a terminal without issue, but will remain all fucked up in IntelliJ IDEA until I delete the .idea
directory and click “Create new project from existing sources”.
Configuring the SBT project in IntelliJ to use the SBT shell doesn’t help at all.
First of all, why does this happen? Which factors contribute to the problem:
And finally, how can this breakage be avoided?
Upvotes: 0
Views: 235
Reputation: 7373
As far as I know, Intellij IDEA creates his own memory structure to represent the actual state of the parsed files, up to a representation that enables all the useful features you get from the IDE (references, usages, docs, squiggles for compiler errors, ...).
This model is not the output of the sbt build. The plugin allows the IDE to create such in-memory representation based on the sbt build-file, and lately, using the sbt engine itself (you need to enable it in the preferences).
Still sbt doesn't allow to keep a memory representation of the output that the IDE can use, hence IDEA's "picture" of the code will sometime diverge from the real compilation output, possibly because some advanced feature in the language and plugins (macros tend to do this for example) are not correctly represented in the IDEA data structure.
Usually when you change something in the build file, IDEA auto-refreshes the build state, or prompts you to do it (when the build file editor is in focus). This should be enough to "align" the build with the IDE.
Yet there are many cases where a complex codebase can permanently show false errors in the IDE.
Right as we speak, there are many ongoing efforts to fix this situation
You can find more information on the Scala Blog Announcement
Upvotes: 0