问题
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 havescalac
installed, and won’t think to doman 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 onscalac
?
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