1

我已经安装了 Eclipse Luna。Help然后我通过->安装了 Scala IDE ,并从这里Install new software添加了带有链接的软件站点。然后我使用这个迷你指南安装了 sbt 0.13 和 sbteclipse并创建了 eclipse 项目。然后我通过将它添加到我的 build.sbt 来安装 (kindda) scalatest。现在看起来像这样:

val scalaTest = "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"

lazy val commonSettings = Seq(
  scalaVersion := "2.11.6"
)

lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    libraryDependencies += scalaTest
  )

然后我从这个例子中创建了一个测试。调用的文件FirstSpec.scala位于testProject/src/test/scala-2.11/testProject/. 所以这里有一个问题:eclipse好像看不到scalaTest。第二行带有import org.scalatest._红色下划线,带有错误描述object scalatest is not a member of package org。而且,按照本指南Run As -> ScalaTest - Suite,我在选择我的测试课程时看不到该选项。同时,当我在测试项目中启动 sbt 会话并键入test命令时,一切都很好。测试启动并通过。

所以我的问题是:

  • build.sbt如果我把它放在's中,为什么 eclipse 看不到最大规模的libraryDependencies?那么 libraryDependencies 有什么意义呢?
  • 为什么sbt test运行测试没有问题?如果 sbt 看到 scalatest,为什么 eclipse 不能?
4

1 回答 1

0

哇,这个解决了我的问题。因此,build.sbt示例可能类似于:

import com.typesafe.sbteclipse.plugin.EclipsePlugin._

EclipseKeys.withSource := true

val scalaTest = "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
val jodaConvert = "org.joda" % "joda-convert" % "1.7"
val joda = "joda-time" % "joda-time" % "2.7"

lazy val commonSettings = Seq(
  scalaVersion := "2.11.6"
)

lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    libraryDependencies += scalaTest
  ).
  settings(
    libraryDependencies += jodaConvert
  ).
  settings(
    libraryDependencies += joda
  )

然后这样做:

rm -rf  ~/.ivy2/cache/

sbt update-classifiers

sbt eclipse
于 2015-04-06T17:46:37.423 回答