我应该在 build.sbt 中包含 scala-compiler 作为依赖项吗? [英] Should I include scala-compiler as a dependency in build.sbt?

查看:46
本文介绍了我应该在 build.sbt 中包含 scala-compiler 作为依赖项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 intellij 中使用 Scala 2.11.7 构建一个项目.我已经将 scalaVersion 设置为 2.11.7,但是当我检查外部库时,我可以看到 scala-compiler:2.11.0.

I'm trying to build a project with scala 2.11.7 in intellij. I've set the scalaVersion to 2.11.7, but when I check the external libraries, I can see scala-compiler:2.11.0.

我是否需要在 build.sbt 中将 scala-compiler:2.11.7 声明为依赖项?docs 令人困惑,似乎是说我确实需要并且然后不要在连续的段落中:

Do I need to declare scala-compiler:2.11.7 as a dependency in build.sbt? The docs are confusing, seemingly saying that I do need to and then not to in consecutive paragraphs:

使用标准库以外的Scala依赖时,添加作为正常的托管依赖项.例如,要依赖 Scala编译器,

When using a Scala dependency other than the standard library, add it as a normal managed dependency. For example, to depend on the Scala compiler,

libraryDependencies += "org.scala-lang" % "scala-compiler" %scalaVersion.value

libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value

为了编译Scala代码,运行scaladoc,并提供一个ScalaREPL,sbt 需要 scala-compiler jar.这不应该是正常的项目的依赖,所以 sbt 添加了对 scala-compiler 的依赖在特殊的私有 Scala 工具配置中.

In order to compile Scala code, run scaladoc, and provide a Scala REPL, sbt needs the scala-compiler jar. This should not be a normal dependency of the project, so sbt adds a dependency on scala-compiler in the special, private scala-tool configuration.

所以...我应该添加还是不添加?

So... should I add it or not?

推荐答案

如果您的项目代码使用 scala-compiler(例如解析或编译 Scala 代码,运行 REPL 等),添加它.否则,不要.这就是为什么第一句话说When 使用标准库以外的 Scala 依赖项..."

If your project's code uses scala-compiler (e.g. to parse or compile Scala code, to run a REPL, etc.), add it. Otherwise, don't. That's why the first quote says "When using a Scala dependency other than the standard library..."

scala-compiler 可能存在,因为您的其他依赖项之一依赖于它(并且该版本是使用 Scala 2.11.0 编译的).

scala-compiler shown in External Libraries is probably there because one of your other dependencies depends on it (and that version was compiled with Scala 2.11.0).

这篇关于我应该在 build.sbt 中包含 scala-compiler 作为依赖项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆