185

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?)

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
KajMagnus
  • 11,308
  • 15
  • 79
  • 127
  • 2
    Similar question (that includes the answer to your question) at http://stackoverflow.com/questions/9415962/how-to-see-all-the-warnings-in-sbt-0-11 – Kristian Domagala Mar 06 '12 at 06:05

3 Answers3

235

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

Lukasz Zuchowski
  • 251
  • 2
  • 11
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
  • 2
    @retronym: `in Global` instead of `in ThisBuild` also works equally well with subprojects—but why is the latter preferred? or is it even? – Erik Kaplun Feb 04 '14 at 01:16
29
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.

Dominykas Mostauskis
  • 7,797
  • 3
  • 48
  • 67
Sandeep Purohit
  • 3,652
  • 18
  • 22
-3

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
ayvango
  • 5,867
  • 3
  • 34
  • 73
  • 1
    Adding Ensime just to get `-deprecation` is a terrible idea. Ensime is for supporting on-the-fly annotation in editors. Besides which, Ensime itself has a host of problems with some kinds of projects (most notably those that use macros heavily). – Zaphod Jun 12 '18 at 23:15
  • ensime plugin is a small companion to the fat language server. You could use it separately. Or could just copy some functionality from it. – ayvango Jun 18 '18 at 00:02