'new dependency not recognised by Maven

Using maven version 3.6.3 and JDK version "openjdk-17"

I've tried using Maven's dependencies so I could use the xstream library in my project. Following a guide I added com.thoughtworks.xstream to my pom.xml file:

enter image description here

I then tried to use xstream, but intellij couldn't resolve "XStream" even though it seems to work for JavaFX just fine. This code does not compile.

enter image description here

EDIT: I loaded a new project, where I used, what I believe to be, up to date versions. Maven 3.8.1, the latest intellij version, and everything else (JDK, openjfx) at version 17.0.2 yet when I try to use "XStream" in my project code (after reloading the maven project) it says "Cannot resolve symbol XStream"

enter image description here

Edit 2: I added junit to the dependencies, it works. I add Gson to the dependencies. It doesn't work.

enter image description here

enter image description here



Solution 1:[1]

I figured out that in the "modules-info.java" file, "requires xstream" is needed. That is all

enter image description here

Solution 2:[2]

One of the following may solve your problem: These are based on my previous experiences.

  1. because may be auto import disabled. re Import maven project.(intellij: press Ctrl+Shift+A then actions - input "reload" find "Reload All Maven Projects").
  2. in my experience, sometimes it does happen that the dependency is not fully received. remove xstream special version folder from .m2 (com->thoughtworks->xstream) and repeat step 1.
  3. maybe repository not valid. check repository source in file settings.xml in .m2 (if exist) or replace to other source.
  4. invalid cache and restart (intellij: file-> invalid caches/restart). This has solved my problem several times.
  5. Your access to the site or repository may be closed. check network policy or use vpn (Poor probability)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Green
Solution 2