Reputation: 21
The project I'm working on uses Scala and SBT. I need to introduce the use of a deprecated method in our code and rather than just giving me an error, sbt is giving me a compile error when I try and compile the code.
Is there a flag or setting somewhere that makes this happen that I can change?
method getDB in class Mongo is deprecated: see corresponding Javadoc
for more information.
[error] lazy val db: com.mongodb.DB = mongoClient.getDB("foo")
[error] ^
[error] one error found
[error] (web/compile:compileIncremental) Compilation failed
[error] Total time: 9 s, completed Jun 2, 2017 7:20:53 AM
Thanks.
Upvotes: 1
Views: 3349
Reputation: 21
In your build.sbt you can set scalaOptions as below :
lazy val exScalacOptions: Seq[String] = Seq(
"-Xlint",
"-feature",
"-deprecation:false",
"-unchecked"
)
After setting the above value you can reference it in your project module settings in build.sbt
as below:
scalacOptions := exScalacOptions
Upvotes: 1
Reputation: 238
SBT gives you a lot of options to set depreciation warnings as errors.
set scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation", "-Xfatal-warnings")
OR
sbt compile -deprecation
OR
You can configure the same in build.sbt file.
You'll have to remove any of the above options if you are using. (Check your compiler settings)
Also, do sbt clean reload compile
.
This worked for me.
Upvotes: 3
Reputation: 15086
Scalac has a flag Xfatal-warnings
that turns warnings into errors. See Is there a way in sbt to convert compiler warnings to errors so the build fails? and https://github.com/scala/bug/issues/8410
A workaround is defining a deprecated trait that calls the method and making its companion object implement that trait:
scala> @deprecated("","") def foo = "I am deprecated"
foo: String
scala> @deprecated("","") trait Foo { def safeFoo = foo }; object Foo extends Foo
defined trait Foo
defined object Foo
scala> foo
<console>:13: warning: method foo is deprecated:
foo
^
res0: String = I am deprecated
scala> Foo.safeFoo
res1: String = I am deprecated
Upvotes: 1