【问题标题】:sbt not showing full output of 'runMain'sbt 未显示“runMain”的完整输出
【发布时间】:2020-04-13 21:31:44
【问题描述】:

当通过runMain 在 sbt 中运行 scala 时,我遇到了一些通过println 写入的输出被切断的问题。如果我通过运行sbt "runMain aw.OutputTry" 运行以下代码,则输出开始在某个时候被切断。

package aw

object OutputTry {
  def main(args: Array[String]) {
    for(i <- 1 to 5000) {
      println(f"${i}")
    }
  }
}

示例输出(我在“...”处截取了输出):

uhu01@DESKTOP-4LSJM58:~/git/spinal$ sbt "runMain aw.OutputTry"
[info] Loading settings for project spinal-build from metals.sbt,plugins.sbt ...
[info] Loading project definition from /home/uhu01/git/spinal/project
[info] Loading settings for project spinal from build.sbt ...
[info] Set current project to aw (in build file:/home/uhu01/git/spinal/)
[info] sbt server started at local:///home/uhu01/.sbt/1.0/server/771a115d7899feb4b3f3/sock
sbt:aw> runMain aw.OutputTry
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[info] Running (fork) aw.OutputTry
[info] 1
[info] 2
[info] 3
...
[info] 963
[info] 964
[info] 965
[success] Total time: 4 s, completed Apr 13, 2020 11:15:55 PM

我假设 sbt 中正在进行一些缓冲,例如在输出前加上[info] 标签?对我来说,这种行为看起来有点像 sbt 中的缓冲区在程序存在后没有被刷新。

我尝试过的事情:

  • 刷新 scala 代码中的输出(通过在循环中调用 Console.flush(),在 println 之后) - 没有帮助
  • 在 sbt 文档中我可以找到设置 logBuffered,我检查了它,它已经设置为 false
  • 将 sbt 调用的输出通过管道传输到文件 - 然后所有行都按预期可见
  • 在退出之前调用 Thread.sleep(1000) 只会解决问题,无论如何都不是解决方案
  • 我首先怀疑我的环境(shell 等),但直接在 scala REPL 中运行代码按预期工作

我在搜索过程中是否忽略了一些 sbt 设置?任何提示如何显示完整输出?

环境:我在 WSL 中的 Ubuntu 18.04 上使用 sbt 1.2.7、Scala 2.11.12 和 openjdk 1.8.0_424

【问题讨论】:

  • 试试 sbt 1.3.9 可能吗?
  • @SethTisue 感谢您的提示,修复了它...作为第一次使用 sbt 的用户,我没有意识到在系统中更新 sbt 版本不足以获得最新版本,我忘记更新project/build.properties中的版本了。你会发布这个作为答案让我接受吗?

标签: scala sbt


【解决方案1】:

sbt 1.2.7 是一个相当老的版本。试用 1.3.9(最新到 2020 年 4 月)。

(请记住,为了保持构建的可重复性,您的 sbt 版本由您的 project/build.properties 文件决定,而不是由您安装的文件决定。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多