问题描述
https://docs.scala-lang.org/overviews/compiler-options/index.html 说
Scala 编译器 scalac 提供了各种编译器选项,也称为编译器标志,用于更改编译程序的方式.
如今,大多数人不再从命令行运行 scalac
.相反,他们使用 sbt、IDE 和其他工具作为编译器的接口.因此,他们甚至可能没有安装 scalac
,也不会考虑做 man scalac
.
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
.
编译器"参考 scalac
?
如果是,他们使用 sbt、IDE 和其他工具作为编译器的接口"?与因此他们甚至可能没有安装 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"?
sbt
依赖于 scalac
吗?
谢谢.
推荐答案
Scala 编译器可以通过 scala-compiler.jar
依赖打包的 API 以编程方式访问,因此 IDE 和 SBT 等工具可以通过此 API 实现自己的客户端前端以驱动编译器功能.scalac
只是一个 bash 脚本,它执行 scala.tools.nsc.MainClass
来自 scala-compiler.jar
的类.
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
.
sbt
依赖于 scalac
吗?
不,sbt 直接使用编译器 API.关于 sbt 需要理解的关键概念之一是构建定义本身就是 Scala 代码,无论是 vanilla 还是 DSL,但仍然是 Scala.版本 用于编译构建定义的 Scala 与用于正确编译项目的 Scala 版本分离.build.sbt
和 project/*.scala
中的构建定义源代码将使用通过 sbt.version=1.2.8
间接指定的 Scala 版本进行编译project/build.properties
中的 code> 设置,而 src/main/scala/*
中的项目源代码将使用通过 scalaVersion 直接指定的 Scala 版本进行编译:= "2.13.1"
build.sbt
中的设置.请注意它们确实有什么不同.将构建定义视为另一个 Scala 应用,使用 sbt API 进行实现.
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.
这篇关于“他们使用 sbt、IDE 和其他工具作为编译器的接口"吗?与“因此他们甚至可能没有安装 scalac"相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!