ScalaTest规范编译错误

ScalaTest规范编译错误,scala,testing,dependencies,Scala,Testing,Dependencies,我是Scala的新手,我正在尝试使用它。我在build.sbt文件中将其依赖项包括为 libraryDependencies++=Seq( “org.scalatest”%”scalatest_2.11“%”2.1.7“%”测试 ) 刷新了sbt,现在它出现在我的外部库文件夹中,所以我认为它安装正确。现在我想做一个测试类。所以我在src/test/scala下创建了一个。我使用了ScalaTest网站frontpage中的示例,它是 import collection.mutable.Stack

我是Scala的新手,我正在尝试使用它。我在build.sbt文件中将其依赖项包括为
libraryDependencies++=Seq(
“org.scalatest”%”scalatest_2.11“%”2.1.7“%”测试
)

刷新了sbt,现在它出现在我的外部库文件夹中,所以我认为它安装正确。现在我想做一个测试类。所以我在src/test/scala下创建了一个。我使用了ScalaTest网站frontpage中的示例,它是

import collection.mutable.Stack
import org.scalatest._

class ExampleSpec extends FlatSpec with Matchers {

  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new Stack[Int]
    stack.push(1)
    stack.push(2)
    stack.pop() should be (2)
    stack.pop() should be (1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new Stack[Int]
    a [NoSuchElementException] should be thrownBy {
      emptyStack.pop()
    }
  }
}
然而,当我运行这个类时,我得到了一个错误

 Error:scalac: bad symbolic reference. A signature in package.class refers to type compileTimeOnly
in package scala.annotation which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
而且

 Error:(4, 27) Reference to class FlatSpec in package scalatest should not have survived past type checking,
it should have been processed and eliminated during expansion of an enclosing macro.
class ExampleSpec extends FlatSpec with Matchers {
                      ^
谁能告诉我是什么问题吗。看起来它没有识别ScalaTest。然而,它在我的外部库中,IntelliJ的自动完成也表明它在那里。在真正开始使用ScalaTest之前,我是否需要刷新其他内容

编辑:

另外,当我运行
test:compile
时,我从sbt获得

  [error] error while loading package, class file needed by package is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Matchers, class file needed by Matchers is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Assertions, class file needed by Assertions is missing.
[error] reference value internal of package scala.reflect.macros refers to nonexisting symbol.
[error] error while loading AbstractSuite, class file needed by AbstractSuite is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Tolerance, class file needed by Tolerance is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading BeWord, class file needed by BeWord is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading ResultOfNotWordForAny, class file needed by ResultOfNotWordForAny is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading NotWord, class file needed by NotWord is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] 8 errors found
[error] (test:compile) Compilation failed
[error]加载包时出错,包所需的类文件丢失。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载匹配器时出错,缺少匹配器所需的类文件。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载断言时出错,断言所需的类文件丢失。
[错误]scala.reflect.macros包的内部参考值引用了不存在的符号。
[错误]加载AbstractSuite时出错,AbstractSuite所需的类文件丢失。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载公差时出错,缺少公差所需的类文件。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载BeWord时出错,BeWord所需的类文件丢失。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载ResultToNotWordForAny时出错,ResultToNotWordForAny所需的类文件丢失。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]加载NotWord时出错,缺少NotWord所需的类文件。
[错误]不推荐使用的对象的引用值$default$2引用了不存在的符号。
[错误]发现8个错误
[错误](测试:编译)编译失败

SBT似乎试图根据scala 2.9.2进行编译。 我想你得加上一个

scalaVersion := "2.10.4"

到您的
build.sbt

当然

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

此外,您可以尝试最新版本。

如果需要使用scala
2.9
进行编译,则更新
JAVA_HOME
IDEA_JDK
以指向
jdk1.7
而不是
jdk1.8

您尝试过
吗;重新加载清洁的test:compile
?我刚刚包括了
test:compile
中的错误。看起来ScalaTest没有正确安装…为了自动匹配ScalarVension(我想您使用的是2.11.x),您最好编写
libraryDependencies++=Seq(“org.ScalaTest”%%“ScalaTest”%%“2.1.7”%”测试”)
,创建未解析的依赖项[错误](*:更新)sbt.ResolveException:未解析的依赖项:org.scalatest#scalatest_2.9.2;2.1.7:未找到[错误]总时间:0秒,已完成2014年5月31日下午7:06:20 `添加
scalaVersion的可能重复:=“2.11.1”
似乎已在IntelliJ内部运行测试。但是,当我运行
test:compile
时,它仍然会创建一个错误
[info]'compiler interface',该错误尚未针对Scala 2.11.1编译。编译。。。[error](compile:compile)编译sbt组件“compiler interface”时出错
因此,我接受您的回答,但您能猜出发生此错误的原因吗?我不确定,但我认为Scala 2.11需要更新的sbt版本。Scala插件的想法与它自己的启动器捆绑在一起。请尝试我提到的链接和SBT文档。这也解决了我的问题(将
scalaVersion:=“2.11.2”
添加到build.SBT)。但是,错误消息和修复都不是很清楚。我不喜欢它。
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test"