IntelliJ 上的 SBT 需要很长时间才能刷新



我有一个相当大的项目(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 0.13.7 开始可用的设置。看看这里:http://www.scala-sbt.org/1.0/docs/Cached-Resolution.html,但基本上你需要为构建中的所有项目启用以下设置:

updateOptions := updateOptions.value.withCachedResolution(true)

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

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

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

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

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

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

您可以阅读有关updateClassifiers慢速的更多信息 https://github.com/sbt/sbt/issues/1930

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

> SBT>构建、执行、部署>构建工具>首选项选中"使用 SBT shell 进行构建和导入"。

我正在使用上述 2 个的组合( ->构建、执行、部署>构建工具> SBT 首选项>选中"使用 SBT 外壳进行构建和导入" - 库尔西耶

使用以下全局构建.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

最新更新