Scala REPL: There were deprecation warnings, re-run with -deprecation

Whenever I used to get the Scala REPL warning message, “There were deprecation warnings, re-run with -deprecation,” I used to have to restart the REPL with the -deprecation flag to see the warning message, like this:

$ scala -deprecation

That works, but sadly, you had to lose your entire REPL session to run it.

Fix: Use “:warnings”

Thanks to the Scala gods, this is no longer necessary in Scala 2.10 (and newer). Now, when you get the REPL “deprecation” warning message, like this:

scala> val x = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>
x: scala.xml.Elem = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

scala> scala.xml.Utility.toXML(x, minimizeTags = true)
warning: there were 1 deprecation warnings; re-run with -deprecation for details
res0: StringBuilder = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

Just type :warnings to see the actual deprecation message, like so:

scala> :warnings
<console>:9: warning: method toXML in object Utility is deprecated: 
Please use `serialize` instead and specify a `minimizeTags` parameter
              scala.xml.Utility.toXML(x, minimizeTags = true)
                                ^

*I bow to the Scala gods in thanks.*

Older Scala? Use “Power user” mode

If you’re forced to use a version of Scala prior to 2.10, you can also take this approach, which is quite a bit harder to remember:

scala> scala.xml.Utility.toXML(x, minimizeTags = true)
warning: there were 1 deprecation warnings; re-run with -deprecation for details
res0: StringBuilder = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> settings.deprecation.value = true
settings.deprecation.value: Boolean = true

scala> scala.xml.Utility.toXML(x, minimizeTags = true)
<console>:36: warning: method toXML in object Utility is deprecated: 
Please use `serialize` instead and specify a `minimizeTags` parameter
              scala.xml.Utility.toXML(x, minimizeTags = true)
                                ^
res1: StringBuilder = <pizza><topping>cheese</topping><topping>sausage</topping></pizza>

That’s quite a bit harder to remember, so I hope you can use Scala 2.10+.