如何在SBT 0.10.0中获得完整的堆栈跟踪?

时间:2011-06-26 01:58:48

标签: scala sbt

我正在使用SBT 0.10.0编译Java和Scala文件的组合。当我通过sbt run运行程序时,它返回一个非零错误,但没有向我显示堆栈跟踪 - 它只是用隐秘的消息静默地失败:

Nonzero exit code: 1

如果我通过scala命令行运行程序,它会显示堆栈跟踪。

有什么方法可以让SBT打印出整个堆栈跟踪?

3 个答案:

答案 0 :(得分:14)

执行sbt进入sbt shell,然后尝试run,然后last run

last <command>输出命令生成的所有内容(所有日志级别,包括[debug])和stacktraces。

答案 1 :(得分:5)

last run,如图here所示,是可行的方法,但如果您正在使用~ run在循环中运行并且只想查看您的内容,则会感到烦人应用程序的例外情况。您可以告诉SBT为这样的任务自动打印堆栈跟踪:

traceLevel in run := 0

进一步参考here

答案 2 :(得分:0)

在SBT 0.13.x中,堆栈跟踪打印出来,因此问题现在可能变得无关紧要了。

jacek:~/sandbox/so/sbt-0.13.1
$ sbt run
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
[info] Compiling 1 Scala source to /Users/jacek/sandbox/so/sbt-0.13.1/target/scala-2.10/classes...
[info] Running MyApp
[error] (run-main-0) java.lang.Exception: exception
java.lang.Exception: exception
    at MyApp$delayedInit$body.apply(Hello.scala:2)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at MyApp$.main(Hello.scala:1)
    at MyApp.main(Hello.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 10 s, completed Jan 16, 2014 12:37:25 AM