9

I just downloaded Intellij on a laptop and I imported a Maven project and the problem is that Intellij do not found any dependency in pom.xml. For example if I try to import hibernate-core or any other dependency I get the error: Dependency org.hibernate-core... not found. What should I do? Any feedback will be appreciated.

elvis
  • 956
  • 9
  • 33
  • 56
  • 3
    Are you able to run the command like mvn clean package from command line ? – Sambit Aug 16 '19 at 07:27
  • 2
    Run `mvn install` command. It will download all the dependencies. – Khalid Shah Aug 16 '19 at 07:31
  • 3
    Sometimes intellij idea do not refresh maven dependency on startup. To do so on the right side of idea there is docked panel with `Maven`. Just open it and click `refresh`. Should reload project and you should see difference. – Paweł Głowacz Aug 16 '19 at 08:01
  • @Sambit Yes I'm able to run the command from command line – elvis Aug 16 '19 at 08:01
  • 1
    @Pawel If I try tu run refresh I get an error: Cannot resolve plugin org.apache.maven.plugins:maven-release-plugin:2.5.3 … 11:02 AM Error running 'refresh': Cannot run program "refresh" (in directory "D:\Projects\my-project"): CreateProcess error=2, The system cannot find the file specified – elvis Aug 16 '19 at 08:07

5 Answers5

19

In case of Intellij Idea, make right click on pom.xml, select maven and then click to reimport. Find below the screenshot.

enter image description here

Sambit
  • 7,625
  • 7
  • 34
  • 65
  • 11
    Looks like this option was replaced with `Reload project`, which solved the problem for me. Why we have to do this by default is beyond me -- extremely, extremely frustrating. – Hatefiend Feb 13 '21 at 12:19
  • Doing the refresh for maven and gradle is unfortunately a way of life in Intellij. 2022 and this still isn't ironed out well. – Nopiforyou Jun 17 '22 at 16:02
  • Doesn't work with 2022.2.3 IntelliJ is really buggy, bad quality IDE compared to VS Code, Eclipse etc – vikramvi Feb 25 '23 at 09:41
9

I solved this issue by running "mvn idea:idea" command. It resolved all module dependencies and also add it to classpath in intellij.

rhizo888
  • 156
  • 1
  • 2
  • can you please explain what that command does? – Fakipo Dec 17 '22 at 13:26
  • Doesn't work with 2022.2.3 IntelliJ, running above command from project directory, it did download many libraries but still I couldn't get rid of basic errors in import. I doubt if project is referring to these downloads or not ? IntelliJ is really pain in doing these basic operations – vikramvi Feb 25 '23 at 09:46
  • I can confirm on June 2023, it works. Sometimes maven --> reload works, sometimes this is needed. – nayakasu Jun 06 '23 at 13:25
4

It may also be worth checking which Maven your IDE is using. You can check it in settings:

enter image description here

We used to have issues with Maven bundled with IntelliJ.

mate00
  • 2,727
  • 5
  • 26
  • 34
  • I helped. I had set up location of my maven directory. When I switched to `Bundled (maven 3)` option then it updated the libraries – Kacper Cichecki Jul 14 '22 at 16:47
  • Doesn't work with 2022.2.3 IntelliJ, there is no Maven option seen under Build Tools. Not sure why does IntelliJ keep changing UI each release ? Most bad quality IDE – vikramvi Feb 25 '23 at 09:48
1

You could also go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Repositories and check that the local maven repository is set.

Same for File -> Settings -> Build, Execution, Deployment -> Remote Jar Repositories where the remote maven repository should be set (something like https://repo1.maven.org/maven2)

robingood
  • 319
  • 2
  • 10
0

After "Maven" > "Reload project" an additional "Build" > "Rebuild project" (in IDEA window menu) was necessary to eliminate all "dependency ... not found" error messages in my case.

S. Doe
  • 685
  • 1
  • 6
  • 25