Search code examples
scalasbtscalacheck

How to make import org.scalacheck.Gen possible in console/Scala REPL?


I'm trying to run ScalaCheck on REPL.

So I made an sbt project with the following build.sbt:

name := "Trying out ScalaCheck"

version := "1.0"

scalaVersion := "2.11.2"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.11.5" % "test"

resolvers +=
  "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

Then, I typed reload and updated to get the library.

Finally, after running console, I tried to import Gen via:

scala> import org.scalacheck.Gen
<console>:7: error: object scalacheck is not a member of package org
       import org.scalacheck.Gen
                  ^

Looking at the docs, I'm not sure why I can't perform this import.


Solution

  • You added Scalacheck to the test scope, so it is available only within it. You should use test:console sbt command instead. See sbt Scopes docs for details.