Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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

like image 635
user3474606 Avatar asked Dec 29 '16 04:12

user3474606


3 Answers

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

like image 114
Justin Kaeser Avatar answered Nov 13 '22 21:11

Justin Kaeser


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!

like image 32
Dawngerpony Avatar answered Nov 13 '22 23:11

Dawngerpony


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

like image 23
Tom Avatar answered Nov 13 '22 21:11

Tom