Ziru Liu
Ziru Liu

Reputation: 85

Cannot Resolve 'junit' with Junit 4.12 in my Maven project

I am having an issue about the junit, the IDE cannot resolve symbol for 'junit' even if I have it installed: enter image description here

If I changed junit to version 4.11, this problem will be solved, but every time I run the test, it will give me error and ask me to use junit 4.12 or higher version.

Here is my project dependencies: enter image description here

Anyone knows how to solve it? I have finish everything, and just waiting for the test. Thanks in advance!

Run 'mvn clean package', gives compilation error: enter image description here

Upvotes: 0

Views: 2882

Answers (2)

Adina Rolea
Adina Rolea

Reputation: 2109

Your project cached an older version. You don't have to set junit version, the annotation spring-boot-starter-test will take care of it. Please consider running clean command in terminal at parent root folder:

mvn clean 

And reimport dependencies by clicking Manven Projects on the right and the first button:

enter image description here

If it does not work, maybe you installed an older version by mistake. You should run:

mvn clean package

UPDATE:

Your maven repository .m2 folder has multiple versions of junit. The simplest way is to delete and build the project again. The .m2 folder will be recreated automatically.

Upvotes: 1

user10367961
user10367961

Reputation:

Two things you could try:

  • Right click on the project, go under Maven and click on Reimport
  • Go to File and select Invalidate Caches / Restart

Upvotes: 1

Related Questions