问题
There is this option in IntelliJ. What does it do? When should we enable it and when not?
[ ] Use sbt shell for build and import (requires sbt 0.13.5+)
回答1:
From the youtrack issue:
Currently in sbt projects, project settings are imported, but compiling is done via the compiler providede by the Scala plugin. In some sbt configurations that don't map well to the IDEA project model, this will result in errors, forcing users to use the shell in addition to the IDE.
For a better integration, we want the Scala plugin to be controlling an sbt shell or server (new functionality in sbt 1.0)
回答2:
IntelliJ Scala Plugin can build Scala projects via
- built-in internal Scala compilation subsystem (Scala Compile Server)
- directly using sbt process (sbt shell)
Built-in Scala compiler
- Configured at:
Preferences | Build, Execution, Deployment | Compiler | Scala Compiler
- Enabled by default
- Responsible for driving in-process scalac API for actual source code to bytecode compilation, performs incremental compilation, compiles project according to defined project structure
- Uses built-in incremental compiler:
Incrementality type: IDEA
- Can optionally use sbt incremental compiler (Zinc):
Incrementality type: Zinc
- IntelliJ imports sbt project structure, converts into IDEA project structure, and use built-in compiler instead of actual sbt
sbt server
- Configured at:
Preferences | Build, Execution, Deployment | Build Tools | sbt
- Not enabled by default:
Use sbt shell
- When enabled IntelliJ delegates all tasks to sbt server
- Responsible for driving in-process scalac API for actual source code to bytecode compilation, performs incremental compilation, compiles project according to defined project structure
- Uses Zinc incremental compiler
- IntelliJ can import sbt project structure and even use sbt directly
- Output from sbt is presented in IntelliJ panes
- IntelliJ can also use sbt directly for tests:
Use UI with sbt
- Instant error highlighting, type-aware highlighting, refactoring, navigation, Scala Worksheets, etc., would still use ItelliJ's built-in presentation compiler even with
Use sbt shell
enabled
Some further thoughts I picked up from IntelliJ Scala gitter channel
- In the future
use sbt shell
might be turned on by default - By default sbt project is converted into IDEA project model on import and after that IDEA compiles it without sbt. If you have more complicated setup you may use sbt shell for your build.
- You may disable scala compile server if you only use SBT shell
- using sbt via the "use sbt shell for builds" will work better for projects that use any advanced build config or code generation and will make refreshing the build faster
来源:https://stackoverflow.com/questions/49213653/use-sbt-shell-for-build-and-import