I am trying to import packages into sbt console
as the following:
scala> import cats.instances.string
<console>:11: warning: Unused import
import cats.instances.string
^
error: No warnings can be incurred under -Xfatal-warnings.
and you can see, I've got an error message.
The content of the build.sbt
is:
scalaVersion := "2.12.8"
scalacOptions ++= Seq(
"-encoding", "UTF-8", // source files are in UTF-8
"-deprecation", // warn about use of deprecated APIs
"-unchecked", // warn about unchecked type parameters
"-feature", // warn about misused language features
"-language:higherKinds",// allow higher kinded types without `import scala.language.higherKinds`
"-Xlint", // enable handy linter warnings
"-Xfatal-warnings", // turn compiler warnings into errors
"-Ypartial-unification" // allow the compiler to unify type constructors of different arities
)
libraryDependencies += "org.typelevel" %% "cats-core" % "1.4.0"
libraryDependencies += "org.tpolecat" %% "atto-core" % "0.6.5"
libraryDependencies += "org.tpolecat" %% "atto-refined" % "0.6.5"
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
What am I doing wrong?
The best solution in this situation is to remove -Xlint
from the Scala options that are used for the console:
scalaVersion := "2.12.8"
scalacOptions ++= Seq(
"-Xlint",
"-Xfatal-warnings"
)
scalacOptions in (Compile, console) ~= {
_.filterNot(Set("-Xlint"))
}
libraryDependencies += "org.typelevel" %% "cats-core" % "1.6.0"
With this configuration, any source code in your project will be compiled with -Xlint
, but any code that's interpreted in the REPL won't be. This is generally exactly what you want: the most thorough safety-checking possible for your project code, but much more flexibility for experimentation in the REPL.