2014-11-14 7 views
20

Ich mag die Definition scalacOptions auf der obersten Ebene wie so (als Beispiel, ohne auf Projektachse vorerst):In sbt, wie überschreiben Sie scalacOptions für die Konsole in allen Konfigurationen?

scalacOptions += "-Ywarn-unused-import" 

Aber dann erkannte ich, dass für console zu streng ist. Also habe ich versucht Einstellung:

scalacOptions in console ~= (_ filterNot (_ == "-Ywarn-unused-import")) 

Aber das hat nicht funktioniert (immer noch (tödliche) Warnungen in der REPL).

verwendete ich inspect zu versuchen und zu verstehen, warum:

> inspect console 
[info] Task: Unit 
[info] Description: 
[info] Starts the Scala interpreter with the project classes on the classpath. 
[info] Provided by: 
[info] {file:/a/}b/compile:console 
[info] Defined at: 
[info] (sbt.Defaults) Defaults.scala:261 
[info] Dependencies: 
[info] compile:console::compilers 
[info] compile:console::initialCommands 
[info] compile:console::fullClasspath 
[info] compile:console::taskTemporaryDirectory 
[info] compile:console::scalaInstance 
[info] compile:console::streams 
[info] compile:console::cleanupCommands 
[info] compile:console::scalacOptions 
[info] Delegates: 
[info] compile:console 
[info] *:console 
[info] {.}/compile:console 
[info] {.}/*:console 
[info] */compile:console 
[info] */*:console 
[info] Related: 
[info] test:console 

Hinweis: console ist

  • von compile:console
  • vorgesehen ist abhängig von compile:console::scalacOptions

dann:

> inspect compile:console::scalacOptions 
[info] Task: scala.collection.Seq[java.lang.String] 
[info] Description: 
[info] Options for the Scala compiler. 
[info] Provided by: 
[info] {file:/a/}b/compile:scalacOptions 
[info] Defined at: 
[info] (sbt.Classpaths) Defaults.scala:1593 
[info] Reverse dependencies: 
[info] compile:console 
[info] Delegates: 
[info] compile:console::scalacOptions 
[info] compile:scalacOptions 
[info] *:console::scalacOptions 
[info] *:scalacOptions 
[info] {.}/compile:console::scalacOptions 
[info] {.}/compile:scalacOptions 
[info] {.}/*:console::scalacOptions 
[info] {.}/*:scalacOptions 
[info] */compile:console::scalacOptions 
[info] */compile:scalacOptions 
[info] */*:console::scalacOptions 
[info] */*:scalacOptions 
[info] Related: 
[info] *:console::scalacOptions 
[info] compile:scalacOptions 
[info] *:scalacOptions 
[info] */*:scalacOptions 
[info] test:scalacOptions 

Hinweis: compile:console::scalacOptions ist

  • von compile:scalacOptions
  • vorgesehen erreicht nicht *:console::scalacOptions (das ist, was ich definiert) in der Delegation Kette

Meine Frage ist, wie zu tun Ich überschreibe scalacOptions für alle Konfigurationen für die Konsole? Ist es möglich, die Delegationskette zu ändern?

Ich möchte vermeiden, scalacOptions in (Compile, console) setzen (wie es für (Test, console) dupliziert werden würde) oder definieren ein val von scalac Optionen.

+0

Siehe auch https: // github.com/typelevel/wartremover/issues/131 –

Antwort

12

Meine Frage ist, wie überschreibe ich scalacOptions für alle Konfigurationen für die Konsole?

Ich glaube nicht, dass wir das Vorhandensein von compile:scalacOptions von SBT Defaults bereitgestellt gegeben werden. Der einzige Bereich mit der höchsten Priorität ist compile:console::scalacOptions. In den meisten Fällen möchte man nicht Compile und Test Einstellungen zu verdrahten, so Konfiguration Scoping höhere Priorität Ich denke nicht, ist ein schlechter Standard.

lazy val commonSettings = Seq(
    scalaVersion := "2.11.4", 
    scalacOptions += "-Ywarn-unused-import", 
    scalacOptions in (Compile, console) ~= (_ filterNot (_ == "-Ywarn-unused-import")), 
    scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value 
) 

Ist es möglich, die Delegation Kette zu ändern?

Nein, das ist nicht möglich. Es gibt eine einzige Instanz von delegates Funktion in BuildStructure, und es wird bei der Ladezeit initialisiert und für alle Aufgaben verwendet. Die Bestellung ist in Scope.delegates erfolgt.

+1

Vielen Dank für Ihre Antwort Eugene, insbesondere die Details/Links zu den Innereien ist sehr wertvoll für mich. Ich denke, es wurde eine Design-Entscheidung getroffen, um die Standardsuche in der Konfiguration vor der Aufgabe zu haben ('compile: scalacOptions' vor' *: console :: scalacOptions'). –

+0

Gibt es eine Möglichkeit, etwas in diese Richtung zu arbeiten? 'ivyConfigurations.value.map (c => scalacOptions in (c, console): = consoleCompilerOptions)' (Tut es nicht) – aij

Verwandte Themen