"Unknown artifact. Not resolved or indexed" scalatest 错误

"Unknown artifact. Not resolved or indexed" error for scalatest

我正在尝试修改 build.sbt 文件以在 IntelliJ IDEA 中添加最大规模的依赖项。控制台中没有错误日志,但是当我将鼠标悬停在下划线上时,我得到了 Unknown artifact. Not resolved or indexed.。我该如何解决这个问题?非常感谢!

这是我用来添加依赖的行:libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.1" % "test"

我的屏幕是这样的:

如果你刚刚添加了依赖,它可能还没有被下载。 Refresh/reimport项目这样做。

如果已经下载,在 IntelliJ 中出现警告的行按 Alt+Enter 和 select "update project resolvers' indexes" quickfix,然后 select "local cache"索引并单击 "update"。

您可以通过检查 "Updated" 列中的日期来验证更新是否有效:

我遇到了同样的问题。文件 -> 无效 Caches/Restart... 为我解决了这个问题。
只是 updating/refreshing 项目在我的案例中不起作用。

在我的情况下,我试过:

  1. Alt + Enter 然后刷新项目。
  2. 更新解析器的本地缓存。
  3. 文件 -> 无效 Caches/Restart。
以上的

None 有效。因此,为了将来参考,这是我针对此问题的解决方案:

  1. 确保 Maven 集成插件已启用,而不是更新解析器的本地缓存,而是更新从未更新的 public。

如果是新安装的 IntelliJ IDEA,此过程可能需要一些时间才能完成下载。

这已经激怒了我几个小时,但我想我终于部分理解了发生了什么。 None 以上建议对我有用。

来自 sbt 文档中的 Automatic Dependency Management

sbt 1.3.0+ uses Coursier to implement dependency management. Until sbt 1.3.0, sbt has used Apache Ivy for ten years. Coursier does a good job of keeping the compatibility, but some of the feature might be specific to Apache Ivy. In those cases, you can use the following setting to switch back to Ivy:

ThisBuild / useCoursier := false

我对我的情况的解释是 IntelliJ 没有对 Coursier 的适当支持(这很奇怪),但是 sbt 使用 Coursier 下载依赖项,然后 IntelliJ 找不到它们,因为它正在我的常春藤缓存中查找. 捂脸

我正在使用 OSX、IntelliJ IDEA Ultimate 2019.2.3、Scala 2.12.8、JDK8(因为我正在使用 Spark)和 sbt 1.3.3。

将以上行添加到我的 build.sbt 文件中解决了我的问题。我的 ~/.ivy2/cache 目录现在是最新的。 Coursier 将其缓存存储在 ~/Library/Caches/Coursier/v1 (docs) 中,但我似乎找不到让 IntelliJ 使用 Coursier 缓存来解析依赖项的方法。欢迎比我更了解 sbt 的人提供有关该主题的更多信息!