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
  • build.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: scalatest ライブラリへの依存関係を追加します。どこ?

4

1 に答える 1

3

追加する必要があります

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

依存関係として認識されるように、ルート ディレクトリに build.sbt を追加します。

于 2012-09-26T13:59:11.660 に答える