Intellij not resolving maven dependencies

已回答

I am using intellij to build my maven project. the project build successfully and run the problem is that intellij is not resolving my dependencies.I tried to restart but the problem is not being resolved. I also tried to clean the logs but no luck. Please assist

12

Here is what worked to me >

1- Right Click the project > Maven > Download Sources 

2- Right Click the project > Maven > Reimport 

 

I think #2 is what made it, so probably no need to #1. Anyway, I do not know why I have to reimport the project to make it work. IDE should be smart enough to pickup the new lib once it's updates in the pom.xml

3

IDE displays a notification to reimport the project after you make a change in pom.xml, you just click on it. Another option is to enable the auto import option:

 

It will be changed in 2020.1 release, please see https://blog.jetbrains.com/idea/2020/01/intellij-idea-2020-1-eap/#maven_and_gradle_importing_updates .

 

0

I may have missed this, as I pulled the pom changes from git then opened the IDE. I will watch for it next time as I am new to the IDE and trying to get used to it. 

0

I faced with the same issue today... again =( Usually I remove .idea and %userdir%/.IntellijIdeaX folder to solve such things, but this time I was too lazy to restore all cfgs and found one more solution:

- go to %projectDir%\.idea folder

- delete compiler.xml file

- check misc.xml file, if <option name=ignoredFiles"> and its <set> somehow contains the module that Idea is unable to resolve - just remove it from there

- re-import maven project

I've wasted so many time for this issue for a lot of times, hope it will help you =)

2

This is also happening to me with latest EAP build #IU-201.6073.9.

Do a maven install on project a to install snapshot version locally. Attempt to use that Snapshot in project B and it doesn't pick it up.

Maven Reimport All did nothing. Going to the specific project, right clicking, maven->reimport actually worked. Something appears to be broken in reimport all.

0

Ben Madore please submit a ticket to support with the logs and more details: Help | Compress Logs and Show in ...

You can attach the files to the report: https://intellij-support.jetbrains.com/hc/requests/new .

0

I had this same issue and found an interesting problem/solution. It turns out that during the rename of my project I somehow ended up with multiple modules pointed at the same source!

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
<module fileurl="file://$PROJECT_DIR$/module2.iml" filepath="$PROJECT_DIR$/modul2.iml" />
</modules>
</component>
</project>

I unloaded the module which no longer represented the project and it appears to be working.

Deleted both modules and re-imported the project as a maven project again. Seems to have worked. Is there a better mechanism to clear out erroneous modules?

 

 

 

 

0

Hi guys,

please try mvn -U idea:idea 

It helped me and everything is working fine right now. This command is responsible for downloading project plugins for Intellij. I hope it will help you as well.

3

I have same problem. How can resolve this issue? İ want to add bcrypt (password hashing) with dependency but no result. Intellij version is 2020.1 ultimate

0

Elxan310 please share a sample project to reproduce the issue.

0

Facing the same issue. All the dependencies are downloaded in .m2/repository as the build passes but some of the imports are not resolved.

0

After lots of wasted time, I installed 2020.1.3 which seemed to work now.

0

For me, the problem is different java versions for project and maven importing settings. 

Go to Preferences -> Build, Execution, Deployment -> Maven -> Importing -> JDK for importer (at the bottom) and set to Use Project JDK (in most cases this should be a case)

 

I don't know how this was changed (maybe I downloaded Java 11) but Intellij, please group some Java versions at the same place if possible

3

Sometimes, in a multi module maven project with SNAPSHOT dependencies, I have to explicitly go to the project classpath and delete the old/duplicate maven dependencies in the classpath as a temporary fix. This besides if these don't work: Reload, Delete .iml, .idea  folders or mvn -U idea:idea .

0

Hello, I am facing quite the same issue. I have one maven project that contains my "domain" classes.

First I run mvn install install and I can see that jar is installed to /Users/user/.m2/repository

Then I change pom.xml of second project to point out to installed dependency. Maven>Reload project works as expected and everything is fine so far. Then when I go again to Editor and try to use the class from first project, I can see the class in recommendation but dependency seems not resolved:

Recommendation works with full classpath:

 

subpackage is not resolved. com.hedwell is resolved only because this project has also com.hedwell as a root level package.

 

----

Edit:

I was wrong, since I tried to import spring-boot project which is not supported by default (not because of intellij but spring-boot) . Adding plugin solves the issue, it creates two jars with mvn package, one that is spring-boot-exec and one that can be used in other projects as dependency: 

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>

 

0

Mihailo Stupar Please see if the workaround from https://youtrack.jetbrains.com/issue/IDEA-239150#focus=streamItem-27-4117814.0-0 helps. If the issue remains try to do:

  • File \ Invalidate caches and restart...

  • Close your project window (and IntelliJ) and remove all *.iml files and the .idea folder.

  • Delete/Rename .m2 maven folder.

  • Run mvn clean install from the command line.

  • Re-import the project into IntelliJ from Existing sources.

 

1

I have sometimes the same issue with sbt. I found that deleting the ./idea/libraries  xml files and a refresh on the project fixes the problem. Might also work on maven.

0

Hello,

I am facing an issue when opening a project my dependencies are not loading i tried everyway but it doesn't get load.

Also maven tool is not showing on the right side.

Maven option is not appearing when right click on pom.xml file

Anyone can please assist why i am facing this?

Here is the screenshot for reference.

Intellij 2021

0

@Egor Klepikov Thanks to you :)
I follow your steps & it works for me (Y)

0

I have had this type of issue quite a few times now (current version - 2021.1.1 Ultimate, IntelliJ IDEA 2021.1.1 (Ultimate Edition, Build #IU-211.7142.45, built on April 30, 2021)
We have nested poms and sometimes Intellij doesn't recognise that, so you can see all the source just none of the external libs, and you can't click off to the external libs (you can even get intellij to build the code when it should fail), so we have soemthing like:

and to get it to be recognised, Ihave to right click the pom and add as a Maven Project

 

 

 

0

i got the same problem but to fix that i just did file-> invalidate caches. hope this can help someone

0

Had the same issue, I had to right-click on the pom file, go to Maven then Reload project.

And the issue was resolved.

0

This comment by Egor Klepikov saved me a ton of time.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003445760-Intellij-not-resolving-maven-dependencies?page=2#community_comment_360002770619 

In my case I had a problem with my maven version setting, so, I opted to use the Bundled Maven in the Maven Home Path.

Preferences > Build, Execution and Deployment > Build Tools > Maven > Maven Home Path

0

I was facing exact same issue as the main issue. When I was going through the comments, I noticed Paolo Magalini  mention .iml file. So I checked my project and noticed the project_name.iml file is located in the project folder. The folder has information on my project dependencies (like list of my dependencies).  However, when I checked my source (src) folder, I can find main.iml file, which does not have the list of my dependencies. So, I deleted the main.iml file, and everything immediately got resolved.

It seems like the main.iml file was being used instead of the project_name.iml file. I'm not sure how the main.iml file got created, probably while I was cloning the project from the GitLab.

0

5 years after this post was created this is still a problem.

Maven builds fine.

IntelliJ complains of a missing org.junit when I try start a debug session or run the app, or initiate a single unit test.

The maven build within Intellij also works. I guess the IntelliJ dependencies ≠ maven dependencies?

I've tried:

- Repair IDE (with and without "drop shared indexes)

- Invalidate Caches

- Performed “reload project” at every level. 

- maven “reload all projects”

The errors are highly variable and non-sensical. I've been working with this project for weeks then one day, it can't find junit??

 

Mess about with the above listed actions then I get:

Then later:

I've spent more time trying to figure out why IntelliJ is not working than I do on actual code.

 

 

0

Hello,

Is it reproducible with new sample project? You may try to copy project to other location, remove IDE related data (.idea folder and .iml file) and reimport project again.  

0

请先登录再写评论。