【问题标题】:Install scalatest in Scala IDE for Eclipse在 Scala IDE for Eclipse 中安装 scalatest
【发布时间】:2015-06-10 07:27:36
【问题描述】:

我已经安装了 Eclipse Luna。然后我通过Help -> Install new software 安装了Scala IDE,并添加了带有来自here 的链接的软件站点。然后我使用this mini-guide 安装了 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
  )

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

所以我的问题是:

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

【问题讨论】:

    标签: eclipse scala scalatest scala-ide sbteclipse


    【解决方案1】:

    哇,this one 解决了我的问题。因此,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-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-20
      • 2014-08-23
      • 1970-01-01
      • 2012-05-04
      相关资源
      最近更新 更多