186

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

1

3 Answers 3

236

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

1
  • 2
    @retronym: in Global instead of in ThisBuild also works equally well with subprojects—but why is the latter preferred? or is it even? Feb 4, 2014 at 1:16
30
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.

-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
2
  • 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, 2018 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, 2018 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.