我创建了一个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中
-
build.sbt
name:=“MyProject”
版本:=“0.1”
scalaVersion:=“2.9.2”
- project / plugins.sbt
addSbtPlugin(“com.typesafe.sbteclipse”%“sbteclipse-plugin”%“2.1.0”)
- project / build.sbt
libraryDependencies =“org.scalatest”%%“scalatest”%“1.8”%“test”
我正在使用SBT 0.11.3和Eclipse Indigo .
edit:
从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>
edit2:
我现在发现控制台上的"sbt test"也不是sbteclipse的问题,而是如何处理测试用例的依赖关系 . 我根据这个问了一个新问题,因为我提出这个问题的假设是错误的:sbt: Add dependency on scalatest library. Where?
1 回答
你应该添加
在根目录中build.sbt以识别为依赖项 .