Use sbt shell for build and import

梦想的初衷 提交于 2020-04-06 02:39:13

问题


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

  1. Configured at: Preferences | Build, Execution, Deployment | Build Tools | sbt
  2. Not enabled by default: Use sbt shell
  3. When enabled IntelliJ delegates all tasks to sbt server
  4. Responsible for driving in-process scalac API for actual source code to bytecode compilation, performs incremental compilation, compiles project according to defined project structure
  5. Uses Zinc incremental compiler
  6. IntelliJ can import sbt project structure and even use sbt directly
  7. Output from sbt is presented in IntelliJ panes
  8. IntelliJ can also use sbt directly for tests: Use UI with sbt
  9. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!