Is “they use sbt, an IDE, and other tools as their interface to the compiler” contrary to “therefore they may not even have scalac installed”?

南笙酒味 提交于 2020-03-21 10:56:05

问题


https://docs.scala-lang.org/overviews/compiler-options/index.html says

Scala compiler scalac offers various compiler options, also referred to as compiler flags, to change how to compile your program.

Nowadays, most people are not running scalac from the command line. Instead, they use sbt, an IDE, and other tools as their interface to the compiler. Therefore they may not even have scalac installed, and won’t think to do man scalac.

Does "the compiler" refer to scalac?

If yes, is "they use sbt, an IDE, and other tools as their interface to the compiler" contrary to "therefore they may not even have scalac installed"?

Does sbt rely on scalac?

Thanks.


回答1:


Scala compiler can be accessed programmatically via an API packaged by scala-compiler.jar dependency, hence tools such as IDEs and SBT can implement their own client frontends over this API to drive compiler functionality. scalac is just a bash script that executes scala.tools.nsc.MainClass class from scala-compiler.jar.


Does sbt rely on scalac?

No, sbt uses compiler API directly. One of the key concepts to understand regarding sbt is that the build definition is itself Scala code, either vanilla or DSL, but Scala nevertheless. The version of Scala used to compile the build definition is separate from the version of Scala used to compile project proper. The build definition source code in build.sbt and project/*.scala will be compiled using Scala version specified indirectly via sbt.version=1.2.8 setting in project/build.properties, whilst project source code proper in src/main/scala/* will be compiled using Scala version specified directly via scalaVersion := "2.13.1" setting in build.sbt. Note how they can indeed differ. Think of the build definition as simply another Scala app which uses sbt API for its implementation.



来源:https://stackoverflow.com/questions/60692971/is-they-use-sbt-an-ide-and-other-tools-as-their-interface-to-the-compiler-co

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