我正在尝试读取SbtTwirltwirlSettings
中定义的值。
有没有办法做到这一点?也许使用sbt inspect
?或者还有其他方法吗?当我试图找出为什么我的 Twirl 模板没有被编译时,我需要阅读这些值。
twirlSettings
,因此,不是您可以使用的密钥sbt inspect
。它是一个Seq[Setting[_]]
. 但是,您可以检查它产生的各个设置。例如:
> inspect compile:compileTemplates::sourceDirectories
检查第 40 行产生的内容:
sourceDirectories in compileTemplates := Seq(sourceDirectory.value / "twirl"),
另一个答案很好,但是使用consoleProject
or的方法更复杂一些eval
。
请参阅以下会话consoleProject
:
[root]> help consoleProject
Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports.
[root]> consoleProject
[info] Starting scala interpreter...
[info]
import sbt._
import Keys._
import _root_.com.typesafe.sbteclipse.plugin.EclipsePlugin._
import _root_.gilt.DependencyGraph._
import _root_.net.virtualvoid.sbt.graph.Plugin._
import _root_.com.typesafe.sbt.SbtGit._
import _root_.com.github.tototoshi.sbt.musical.Plugin._
import _root_.com.timushev.sbt.updates.UpdatesPlugin._
import _root_.play.twirl.sbt.SbtTwirl.autoImport._
import _root_.sbt.plugins.IvyPlugin
import _root_.sbt.plugins.JvmPlugin
import _root_.sbt.plugins.CorePlugin
import _root_.sbt.plugins.JUnitXmlReportPlugin
import _root_.play.twirl.sbt.SbtTwirl
import currentState._
import extracted._
import cpHelpers._
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> SbtTwirl
res0: play.twirl.sbt.SbtTwirl.type = play.twirl.sbt.SbtTwirl
访问SbtTwirl
和使用 Scala 你可以做任何你想做的事,但要小心你的猜测,因为生活consoleProject
可能并不像现在那么容易build.sbt
——没有.value
宏在你的指尖。不过,您在 Scala 世界中。
scala> SbtTwirl.twirlSettings.foreach { s => println(s) }
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),includeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,38)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),excludeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,39)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,40)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,42)
setting(ScopedKey(Scope(This,Global,This,This),watchSources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,48)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),target)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,50)
setting(ScopedKey(Scope(This,This,This,This),twirlCompileTemplates)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,52)
setting(ScopedKey(Scope(This,This,This,This),sourceGenerators)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,54)
setting(ScopedKey(Scope(This,This,This,This),managedSourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,55)
使用eval
也可能有用。
[root]> help eval
eval <expression>
Evaluates the given Scala expression and prints the result and type.
[root]> eval SbtTwirl.twirlSettings
[info] ans: Seq[sbt.Setting[_]] = List(setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),includeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,38), setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),excludeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,39), setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,40), setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,42), setting(ScopedKey(Scope(This,Global,This,This),watchSources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,48), setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),target)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,50), setting(ScopedKey(Scope(This,This,This,This),twirlCompileTemplates)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,52), setting(ScopedKey(Scope(This,This,This,This),sourceGenerators)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,54), setting(ScopedKey(Scope(This,This,This,This),managedSourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,55))
[root]> eval SbtTwirl.twirlSettings.foreach { e => println(e) }
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),includeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,38)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),excludeFilter)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,39)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,40)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),sources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,42)
setting(ScopedKey(Scope(This,Global,This,This),watchSources)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,48)
setting(ScopedKey(Scope(This,This,Select(twirlCompileTemplates),This),target)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,50)
setting(ScopedKey(Scope(This,This,This,This),twirlCompileTemplates)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,52)
setting(ScopedKey(Scope(This,This,This,This),sourceGenerators)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,54)
setting(ScopedKey(Scope(This,This,This,This),managedSourceDirectories)) at LinePosition((play.twirl.sbt.SbtTwirl) SbtTwirl.scala,55)
[info] ans: Unit = null