【问题标题】:SBT on IntelliJ takes a very long to time refreshIntelliJ 上的 SBT 需要很长时间才能刷新
【发布时间】:2019-01-10 03:39:39
【问题描述】:

我有一个相当大的项目(超过 15 个子项目),它有很多外部依赖项。当我在build.sbt 中更改一行然后点击刷新时,IntelliJ 会在很长一段时间内(30 多分钟)继续解决各种依赖关系。

它应该这么慢吗?从命令行使用 sbt 不会超过 30 秒左右。

我正在使用 -

Macbook pro mid 2015 with 16 GB ram
IntelliJ IDEA Ultimate 2017.2.5
sbt 0.13.13 
scala 2.11.11

【问题讨论】:

  • 您是否禁用了“下载 sbt 源”选项?您也可以尝试启用“使用 SBT shell 进行构建和导入”选项。
  • “下载 SBT 源”未选中。 “下载库源”被选中。嘿,SBT shell 成功了。非常感谢:-)

标签: scala intellij-idea sbt


【解决方案1】:

缓存依赖解析可以提供帮助,这是从 sbt 0.13.7 开始提供的设置。看看这里:http://www.scala-sbt.org/1.0/docs/Cached-Resolution.html,但基本上您需要为构建中的所有项目启用以下设置:

updateOptions := updateOptions.value.withCachedResolution(true)

使用此设置,我能够将 IntelliJ 项目刷新时间从 15 分钟缩短到 3 分钟。仍然不理想,但更易于管理。

有一些注意事项,因为它是一个实验设置,它们在该页面中进行了描述。基本上,如果你有 SNAPSHOT 依赖项,启用它只会让事情变得更糟,所以要注意这一点。

【讨论】:

  • 谢谢。我现在启用了 SBT shell,刷新时间缩短到了几分钟。我也会尝试缓存的分辨率,如果有更多帮助,请在此处更新。
【解决方案2】:

Kakaji 和 Haspemulator 的回答帮助我在大约 40 个项目构建中将导入时间缩短到大约 3 分钟。除此之外,我发现 IntelliJ SBT 导入中的大部分时间都花在了从 Ivy 获取依赖项作为 updateClassifiers 命令的一部分。

如果您在导入项目时启用了“库源”复选框,则每次执行导入时都会发生这种情况。如果您还检查“sbt 源”,我希望它会更慢,因为这意味着要解析更多的库。

加快updateClassifiers 的一种方法是使用coursier 进行依赖关系解析。我刚刚在 project/plugins.sbt 中添加了以下行,现在它会在大约 1 分钟内导入。

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.1")

你可以在https://github.com/sbt/sbt/issues/1930阅读更多关于updateClassifiers变慢的信息​​

【讨论】:

    【解决方案3】:

    我按照@y.bedrov 的建议在 IntelliJ 中启用了 SBT shell,现在刷新速度与命令行一样快!

    Preferences > Build, Execution, Deployment > Build Tools > SBT > 勾选“Use SBT shell for build and import”。

    【讨论】:

    • FWIW,启用此功能可使我的构建刷新时间更长。可能(除其他外)因为它会在启动时两次加载项目,然后发出reload 命令。我的构建很大(50 多个项目),所以,我猜,应该使用的实际优化集取决于构建大小。无论如何,如果它对你有帮助,那就太好了。
    【解决方案4】:

    我正在使用上述 2 的组合( - Preferences > Build, Execution, Deployment > Build Tools > SBT > 勾选“Use SBT shell for build and import” - 快递员

    使用以下全局 build.sbt :

        // file: ~/.sbt/0.13/plugins/build.sbt
        // purpose: add jar utils useful for development, but not wanted to projects' build.sbt
    
        // much better depts resolvement and fetching
        // usage: sbt update
        // https://github.com/coursier/coursier#why
        resolvers += Resolver.sonatypeRepo("snapshots")
        addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-SNAPSHOT")
    
    
        // enable this one if you want to use the local artifacts in your local repo's
        // ~/.ivy2/local/
        // ~/.ivy2/cache/
        // instead of the remote ones
        // updateOptions := updateOptions.value.withLatestSnapshots(false)
    
    
        resolvers ++= Seq(
           "typesafe" at "https://dl.bintray.com/typesafe/ivy-releases/",
           "Maven External Releases" at "https://artifactory-espoo1.ext.net.nokia.com/artifactory/public-maven-remotes/"
        )
    
    
        // eof file: ~/.sbt/0.13/plugins/build.sbt
    

    【讨论】:

      猜你喜欢
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 2015-12-28
      • 2013-10-11
      • 2012-12-04
      相关资源
      最近更新 更多