-1

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

James Green
  • 125
  • 12
  • Providing the maven version and JDK version can make it easy for others to help you. – WENJUN CHI Feb 24 '22 at 01:26
  • Did you reload your maven project after modifying your pom? – tgdavies Feb 24 '22 at 01:32
  • Few things to do: 1. Check that you have the import in your file. IntelliJ would normally prompt to add one, so this probably isn't the case. 2. Check that the repo maven is resolving is from has your dependency. If you're using Central, you're probably safe. 3. Rebuild/reload your project. Sometimes there was a separate build error and it didn't get to resolving dependencies yet. 4. Give up and sacrifice yourself to the will another build tool. – Aliics Feb 24 '22 at 01:41
  • @WENJUNCHI I have added these – James Green Feb 24 '22 at 13:40
  • @tgdavies I have reloaded the project twice now, to no effect. I also copy-pasted the XML code into the pom file from the XStream website. – James Green Feb 24 '22 at 13:51
  • What happens if you run `mvn package` at the command line? – tgdavies Feb 24 '22 at 23:19
  • You use JDK17, but why your maven.compiler.source and maven.compiler.target is 11? I use JDK17 maven3.8.1, import XStream, everything is ok. – WENJUN CHI Feb 25 '22 at 02:04
  • @WENJUNCHI I've started a new project to test everything. When the project is created by Intellij, the source/target for the maven compiler is set to 11 by default. What should it be? My Maven is now up to date alongside my Intellij version. And I've update the JavaFX version – James Green Feb 28 '22 at 11:36

2 Answers2

2

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

enter image description here

James Green
  • 125
  • 12
0

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)
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 06 '22 at 10:14