sbt 项目找不到 ScalaCheck

sbt project cannot find ScalaCheck

使用sbt测试代码

package examples
import org.specs2._

class ScalaCheckExamplesSpec extends Specification with ScalaCheck { def is = s2"""
  startsWith ${ prop { (a: String, b: String) => (a+b) must startWith(a) } }
  endsWith   ${ prop { (a: String, b: String) => (a+b) must endWith(b) } }
  substring  ${ prop { (a: String, b: String) => (a+b).substring(a.length) === b } }
  substring  ${ prop { (a: String, b: String, c: String) => (a+b+c).substring(a.length, a.length+b.length) === b } }                                                                                                                       """
}

使用 sbt 配置:

libraryDependencies ++= Seq(
    "org.specs2" %% "specs2-core" % "3.8.5" % "test",
    "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
)

无法找到 class ScalaCheck:

ScalaCheckExamplesSpec.scala:11: not found: type ScalaCheck
[error] class ScalaCheckExamplesSpec extends Specification with ScalaCheck {

如何解决错误?

你需要:

libraryDependencies ++= Seq(
  "org.specs2" %% "specs2-core" % "3.8.5" % "test",
  // the scalacheck lib will come as a transitive
  // dependency
  "org.specs2" %% "specs2-scalacheck" % "3.8.5" % "test"
)