当前位置: 动力学知识库 > 问答 > 编程问答 >

scala - 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: