How to access Scala Reflection Library's string evaluation features?

It seems something changed in Scala 2.13.3 in relation to some older version (2.12?) regarding reflection.

I have this in build.sbt:

libraryDependencies += "org.scala-lang" % "scala-reflect" % "2.13.3"

but import scala.reflect is not found.

This should be the same in 2.12 and 2.13.
If you need toolbox.eval(...) (at runtime) you should add

libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.13.3"

(this includes "scala-reflect")

import scala.reflect.runtime
val toolbox = ToolBox(runtime.currentMirror).mkToolBox()

If you need context.eval(...) in macros (at compile time) then "scala-reflect" should be enough.

Thanks Dmytro,

So it seems to be a problem with Intellij here…

Also, I had a variable called scala to make things worse.

You can import like

import _root_.scala.reflect
1 Like