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

3

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

Cajolery answered 6/3, 2012 at 5:46 Comment(1)
Similar question (that includes the answer to your question) at #9416462Guano
P
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

Pituri answered 6/3, 2012 at 6:11 Comment(1)
@retronym: in Global instead of in ThisBuild also works equally well with subprojects—but why is the latter preferred? or is it even?Melva
P
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.

Peracid answered 5/7, 2016 at 17:37 Comment(0)
D
-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
Dockyard answered 13/9, 2016 at 19:7 Comment(2)
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).Sherer
ensime plugin is a small companion to the fat language server. You could use it separately. Or could just copy some functionality from it.Dockyard

© 2022 - 2024 — McMap. All rights reserved.