Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import scala.reflect.runtime.universe

I'd like to play around with reflection in scala (2.10.2) by following the example in this tutorial. things work fine when I start the sbt (version 0.13) and import scala.refelct.runtime.universe._

scala> import scala.reflect.runtime.universe._                                                                                                                                       │~                                                                                                                                                                                   
import scala.reflect.runtime.universe._

but when I try to put the sample code to an object like

object ReflectExample {
   import scala.reflect.runtime.universe._
   /*
    the rest of the Example
   */
}

and compile the code by sbt compile I see the following error message like:

[error]  object runtime is not a member of package reflect                                                                                                                                                                                                                                                       
[error]     import scala.reflect.runtime.universe._
like image 531
Haiyuan Zhang Avatar asked Aug 07 '14 18:08

Haiyuan Zhang


2 Answers

As explained in sbt's documentation, you need to add this line to the libraryDependencies field of your project in build.sbt:

"org.scala-lang" % "scala-reflect" % scalaVersion.value

like image 166
jopasserat Avatar answered Sep 21 '22 12:09

jopasserat


You may want to try adding dependency to http://mvnrepository.com/artifact/org.scala-lang/scala-reflect

like image 40
cchantep Avatar answered Sep 21 '22 12:09

cchantep