2

我创建了一个 sbt 项目。在命令行调用 sbt compile 效果很好:

$:[...]/Scala-Parser$ sbt compile
[info] Loading global plugins from /home/[...]/.sbt/plugins
[info] Loading project definition from [...]/Scala-Parser/project
[info] Set current project to MyProject (in build file:[...]/Scala-Parser/)
[info] Updating {file:/home/heinzi/ftanml/Scala-Parser/}default-d86d09...
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Done updating.
[info] Compiling 19 Scala sources to [...]/Scala-Parser/target/scala-2.9.2/classes...
[warn] there were 3 unchecked warnings; re-run with -unchecked for details
[warn] one warning found
[success] Total time: 7 s, completed 26.09.2012 11:01:18

外部库不会添加到 lib_managed 目录,而是添加到 ~/.ivy2。尽管如此,在我的类中编译和使用依赖项工作正常。创建一个 Eclipse 项目也可以正常工作:

$:[...]/Scala-Parser$ sbt eclipse
[info] Loading global plugins from /home/[...]/.sbt/plugins
[info] Loading project definition from [...]/Scala-Parser/project
[info] Set current project to MyProject (in build file:[...]/Scala-Parser/)
[info] About to create Eclipse project files for your project(s).
[info] Successfully created Eclipse project files for project(s):
[info] MyProject

但是 Eclipse 然后无法编译该项目,因为它缺少一个应该由托管库提供的包(即未找到 scalatest)。为什么这个托管依赖项没有添加到 Eclipse 中?

这是我的项目定义文件:

  • 来源在 src/main/scala 各自的 src/test/scala
  • 构建.sbt

    名称:=“我的项目”

    版本:=“0.1”

    scalaVersion := "2.9.2"

  • 项目/plugins.sbt

    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")

  • 项目/build.sbt

    libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test"

我正在使用 SBT 0.11.3 和 Eclipse Indigo。

编辑:

从 Eclipse 创建的 .classpath 如下所示:

<classpath>
  <classpathentry output="target/scala-2.9.2/classes" path="src/main/scala" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/classes" path="src/main/java" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/test-classes" path="src/test/scala" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/test-classes" path="src/test/java" kind="src"></classpathentry>
  <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"></classpathentry>
  <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry>
  <classpathentry path="bin" kind="output"></classpathentry>
</classpath>

编辑2:

我现在发现控制台上的“sbt test”也不起作用。所以我认为这不是 sbteclipse 的问题,而是如何处理测试用例的依赖关系。我据此提出了一个新问题,因为我提出这个问题的假设是错误的:sbt: Add dependency on scalatest library。在哪里?

4

1 回答 1

3

你应该添加

libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test"

在根目录中构建.sbt 以被识别为依赖项。

于 2012-09-26T13:59:11.660 回答