2017-06-02 25 views
0

造成編譯錯誤,我工作的項目使用Scala和SBT。我需要在代碼中引入不推薦使用的方法,而不僅僅是給我一個錯誤,當我嘗試編譯代碼時,sbt給我一個編譯錯誤。爲什麼是一個棄用警告在SBT

有沒有使這種情況發生,我可以改變一個標誌或設置的地方?

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 

謝謝。

回答

0

Scalac有一個標誌Xfatal-warnings,輪流警告變爲錯誤。見Is there a way in sbt to convert compiler warnings to errors so the build fails?https://github.com/scala/bug/issues/8410

一種解決方法是定義一個過時特徵調用該方法,並使得其同伴對象實現一個特點:

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 
+0

該標誌是在我build.sbt實際設置,但我已經刪除了我仍然收到編譯錯誤。 – Kohl

+0

你可以用你得到的錯誤編輯你的問題嗎? –

+1

@Kohl更改後重新加載sbt配置(在sbt提示符下重新啓動sbt或鍵入reload)? – jan0sch