【问题标题】:Scala SBT compile hangs (SBT 1.5.0, Scala 2.13.5, Java 11.0.10)Scala SBT 编译挂起(SBT 1.5.0、Scala 2.13.5、Java 11.0.10)
【发布时间】:2021-04-12 19:11:03
【问题描述】:

在我的项目中,Scala/SBT 构建在compile 步骤中无限挂起。重现:

git clone https://github.com/gdiet/backup.git
cd backup
# fist the good case - compiles in less than 30s (when dependencies are fetched etc. etc.)
git checkout e8bdc8a1e878bd15129f08b20df51d54ebd86e4a
sbt compile
# now the problem - compile hangs infinitely
git checkout b273a531c19ad68600026429643e13c6d2761c16
sbt compile

(抱歉,我无法创建一个最小的演示示例。)“​​干净”没有帮助。我可以使用 SBT、IntelliJ IDEA 和 Docker 在我的 Linux 系统上重现该问题。对于 Docker,运行

# reproduce the problem in Docker - compile hangs infinitely
git checkout b273a531c19ad68600026429643e13c6d2761c16
./build-app.sh

问题:

  1. 如何确定这是 scalac 问题还是 SBT 问题,以便打开错误?
  2. 如何获得有关构建挂起原因的更多信息,以便尝试避免该问题?

【问题讨论】:

  • 这两次提交之间有什么显着变化?
  • 好像和sbt没有关系,如果你运行git diff e8bdc8a1e878bd15129f08b20df51d54ebd86e4a..b273a531c19ad68600026429643e13c6d2761c16你会发现很多变化。此外,如果您只是恢复到旧的 sbt (1.4.5) - 它也会挂起

标签: scala sbt


【解决方案1】:

我怎样才能...? 我只需要将问题缩小到最小范围。这就是我到达那里的方式:

  • 找到一个最小更改,其中编译工作之前和之后挂起。
  • 将问题代码隔离到单独的 Scala 类/对象/项目中。
  • 检查是只有sbt compile 挂起还是scalac 也挂起(确实如此)。在后一种情况下,scalac 是罪魁祸首。
  • 至于避免这个问题:详细调查显示我使用了Vector,而类型系统应该需要LazyList。将其更改为LazyList,一切都按预期工作。 (请参见下面的最小示例。)

我现在导致 scalac (scala 2.13.5) 挂起的最小示例是:

object CompileHangs {
  def read1(): LazyList[Either[(Int, Int), String]] = ???
  def read2(): Option[LazyList[Either[(Int, Int), String]]] = ???

  def read(): LazyList[Either[(Int, Int), String]] =
    read1().flatMap {
      case Right(_) => LazyList()
      case Left(value) =>
        read2().getOrElse(
          // LazyList instead of Vector would be the correct thing here.
          // Use it and everything works as expected.
          Vector(Left(value))
        )
    }
}

有趣的一面观察:如果我将Either[(Int, Int), String] 切换到Either[Int, String],编译工作正常,即使使用Vector,虽然我预计会出现类型检查错误。

我现在将为scalac 创建一个错误报告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 2020-08-07
    • 2011-12-24
    相关资源
    最近更新 更多