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

I'm trying to modify the build.sbt file to add scalatest dependencies in IntelliJ IDEA. There's no error log in the console but I got a Unknown artifact. Not resolved or indexed. when I hovered my mouse over the underline. How do I solve this? Many thanks in advance!

This is the line I used to add dependency: libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.1" % "test"

And here is what my screen looks like: enter image description here


Solution 1:

If you just added the dependency, it might not have been downloaded yet. Refresh/reimport the project to do so.

If it has already been downloaded, press Alt+Enter in IntelliJ on the lines with the warning and select the "update project resolvers' indexes" quickfix, then select the "local cache" index and click "update".

You can verify that the update worked by checking the date in the "Updated" column:

Resolver indexes

Solution 2:

This has been infuriating me for a couple of hours now, but I think I finally understand partly what's going on. None of the above suggestions worked for me.

From Automatic Dependency Management in the sbt docs:

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

My interpretation of my situation is that IntelliJ doesn't have proper support for Coursier (which is strange), but sbt is using Coursier to download dependencies, then IntelliJ can't find them because it's looking in my ivy cache. facepalm

I'm using OSX, IntelliJ IDEA Ultimate 2019.2.3, Scala 2.12.8, JDK8 (because I'm working with Spark) and sbt 1.3.3.

Adding the above line to my build.sbt file solved the problem for me. My ~/.ivy2/cache directory is now up to date. Coursier stores its cache in ~/Library/Caches/Coursier/v1 (docs) but I can't seem to find a way to get IntelliJ to use the Coursier cache to resolve dependencies. Any more information on the subject from someone who knows more about sbt than me would be welcome!

Solution 3:

I had the same problem. File -> Invalidate Caches/Restart... fixed the issue for me.
Just updating/refreshing project didn't work in my case.

Solution 4:

In my situation, I tried:

  1. Alt + Enter then Refresh Project.
  2. Update Resolvers' Local cache.
  3. File -> Invalidate Caches/Restart.

None of the above worked. So for future reference, here is my solution for this issue:

  1. Ensure Maven Integration plugin is enabled, and instead of updating Resolvers's Local cache, update the public which is Never Updated.

This process may take some time to finish download if it's a newly installed IntelliJ IDEA.