简体   繁体   中英

Mysterious Scalaz NoClassDefFoundError and scalaz.InvariantFunctor errors

I have the following build.sbt, and am running Scala 2.10.4 with IntelliJ managing sbt, and refreshing the project based on the sbt build file. Everything was working fine, until i added scalaz-streams -- I cannot seem to be able to use scalaz.concurrent.Task without encountering one of the following errors:


// build.sbt

name := "ScalazStreamsAkka"

version := "1.0"


resolvers += "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"

resolvers ++= Seq(
  Resolver.sonatypeRepo("releases"),
  Resolver.sonatypeRepo("snapshots")
)

libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0"

libraryDependencies += "org.scalaz" %% "scalaz-concurrent" % "7.1.0"

//libraryDependencies += "org.scalaz.stream" %% "scalaz-stream" % "0.5a"

libraryDependencies += "org.typelevel" %% "scodec-core" % "1.3.0"

libraryDependencies ++= Seq(
  "com.chuusai" % "shapeless_2.10.4" % "2.0.0"
)

With this build.sbt, This error occurs:

scala> import scalaz.concurrent.Task
import scalaz.concurrent.Task

scala> Task
java.lang.IncompatibleClassChangeError: Class scalaz.concurrent.Task$$anon$1 does not        implement the requested interface scalaz.InvariantFunctor

If I uncomment "scalaz-concurrent", then the same error occurs:

scala> import scalaz.concurrent.Task
import scalaz.concurrent.Task

scala> Task
java.lang.IncompatibleClassChangeError: Class scalaz.concurrent.Task$$anon$1 does not     implement the requested interface scalaz.InvariantFunctor`

If i try to run these up-to-date examples...

val ones: Process[Task,Int] = Process.constant(1)

/* A stream which emits `0, 1, 2 ... 99`. */
val zeroTo100: Process[Task,Int] = Process.range(0,100)

The same error also occurs.


Other times, I encountered this error:

scala>     val expensiveInt: Task[Int] = Task { 41 + 1 }
java.lang.NoClassDefFoundError: Could not initialize class scalaz.concurrent.Task$

Does anyone know how I can use scalaz streams without encountering these strange errors? I am trying to use scalaz-streams with akka actors and futures, as well as possibly shapeless and scodec.

I fixed it myself. The solution was to make a new intellij project, remove shapeless + scodec, and make the akka dependency resolved by SBT (by adding a libraryDependency +=), instead of intellij's maven component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM