How to "re-run with -deprecation for details" in sbt?

Sbt

Sbt Problem Overview


When I compile Scala code, by running sbt compile, SBT says:

$ sbt compile
...
[warn] there were 5 deprecation warnings; re-run with -deprecation for details
...

How do I do that? (From within SBT?)

Sbt Solutions


Solution 1 - Sbt

sbt shell

While in sbt shell (if you don't want to change your build.sbt):

$ sbt
> set ThisBuild/scalacOptions ++= Seq("-unchecked", "-deprecation")
> compile
> exit

Due to in ThisBuild, set applies the settings to all sub-projects, as well.

Command Line

You could also run the above as a single command on command line.

sbt '; set ThisBuild/scalacOptions ++= Seq("-unchecked", "-deprecation") ; compile' 

The trick is to use ; (semicolons) to separate commands and ' (ticks) to include all ;-separated commands as a single argument to sbt.

sbt < 1.x

Instead of ThisBuild/scalacOptions use scalacOptions in ThisBuild

Solution 2 - Sbt

scalacOptions := Seq("-unchecked", "-deprecation")

Add this setting to your build.sbt, and, if you have a multi-module project, add it to every project's settings.

Solution 3 - Sbt

As times flows new solutions are emerged. So, now you could re-run the scala compiler without issuing entire project rebuild.

You need to install ensime-sbt plugin:

addSbtPlugin("org.ensime" % "sbt-ensime" % "1.0.0")

After that you could use the ensimeCompileOnly task to compile single file. SBT allows per tasks settings configuration, so you could change for that tasks only:

set scalacOptions in (Compile, EnsimeKeys.ensimeCompileOnly) += "-deprecation"
ensimeCompileOnly src/main/scala/MyFile.scala

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKajMagnusView Question on Stackoverflow
Solution 1 - SbtEugene YokotaView Answer on Stackoverflow
Solution 2 - SbtSandeep PurohitView Answer on Stackoverflow
Solution 3 - SbtayvangoView Answer on Stackoverflow