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

16,398

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.

Share:
16,398

Related videos on Youtube

user3474606
Author by

user3474606

Updated on June 13, 2022

Comments

  • user3474606
    user3474606 almost 2 years

    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

    • JonasVautherin
      JonasVautherin over 7 years
      Is it working when you run sbt compile in command line? I tried it and it is working for me. I am not using IntelliJ, though.
    • user3474606
      user3474606 over 7 years
      Yea compile works, but scalatest is for testing right? I don't see it in the library. I'm quite new to scala..
    • Justin Kaeser
      Justin Kaeser over 7 years
      If it resolves in the console, it's probably just not in the index IntelliJ makes of the local ivy repo. Try the quickfix (Alt+Enter) to update the index.
    • user3474606
      user3474606 over 7 years
      @JustinKaeser I tried that but the console only showed new lines. No messages or anything. I'm using a Mac. Does it make any difference?
    • Justin Kaeser
      Justin Kaeser over 7 years
      Sorry, I meant pressing Alt+Enter in IntelliJ on the lines with the warning and selecting the "update project resolvers' indexes" quickfix, then select the "local cache" index and click "update"
    • user3474606
      user3474606 over 7 years
      Thank you @JustinKaeser! It worked, but I might have accidentally "injected references", like add that word (where the warnings were) to a dictionary. I'm not sure if that made the warnings gone. How can I check if the project indexes were indeed updated?
    • Jeffrey Aguilera
      Jeffrey Aguilera almost 7 years
      Quick fix does not work for me. Local ivy repo updated seconds ago, and old artifacts still appear as "Unknown artifact". Same problem with Analyze > Inspect Code ...
  • user3474606
    user3474606 over 7 years
    Thanks! @JustinKaeser do you know how to bring up this window when the warning is gone and there's no longer underlines?
  • Justin Kaeser
    Justin Kaeser over 7 years
    It's in the File / Project Structure dialog under Project Settings / Modules on the SBT tab of any *-build module. Note that there's an issue that with remote repos that don't contain a proper index, they will never properly update.
  • salvob
    salvob about 7 years
    This is still a bug in IntelliJ for every dependency added build.sbt. Quite annoying, hopefully they'll fix it soon. Here the link
  • Rumid
    Rumid about 7 years
    After updating cache one may need to refresh the project.
  • tunesmith
    tunesmith over 3 years
    This was the relevant answer for me in 2020, version 2020.2 . It also looks like after you rebuild, you can comment the line out (until the next time it complains).
  • Andrzej Lichnerowicz
    Andrzej Lichnerowicz over 3 years
    Indeed. This is what it took, to get 2020.02 working. Thanks!
  • Emptyless
    Emptyless over 3 years
    I received an java.lang.IllegalArgumentException when using only ThisBuild / useCoursier = false. Using Coursier for updateSbtClassifiers according to github.com/sbt/sbt/issues/5263#issuecomment-626462593 does allow IntelliJ to index but also resolves the newly introduced error