Intellij idea cannot resolve anything in maven

2019-01-08 04:12发布

I'm new to Intellij Idea, i just import a project with pom.xml, but the ide didn't resolve anything in maven dependencies.

Anything defined in pom.xml dependencies when import in code raise an error cannot resolve symbol xxxxx

But mvn install will work, i try import the dependencies in Project Settings/Libraries in .jar files, then it works, but could the ide resolve libraries defined in pom.xml? i don't want to do that everytime.

Additionnal info:

IDEA version: 12.0.3, OS : windows 7, reimport does not work, maven version : 3.0.4, maven dependencies does not exists under Exernal Libraries.

there is no exceptions in idea.log...

18条回答
Ridiculous、
2楼-- · 2019-01-08 04:37

In IntelliJ 12.1.4 I went through Settings --> Maven --> Importing and made sure the following was selected:

  1. Import Maven projects automatically
  2. Create IDEA modules for aggregator projects
  3. Keep source...
  4. Exclude build dir...
  5. Use Maven output...
  6. Generated souces folders: "detect automatically"
  7. Phase to be...: "process-resources"
  8. Automatically download: "sources" & "documentation"
  9. Use Maven3 to import project
    • VM options for importer: -Xmx512m

This took me from having a lot of unresolved import statements to having everything resolved. I think the key here was using Maven3 to import project... Hopefully this helps.

查看更多
迷人小祖宗
3楼-- · 2019-01-08 04:38

Just encountered the same problem after IntelliJ update. My fix: right click on the project, then maven -> reimport.

查看更多
等我变得足够好
4楼-- · 2019-01-08 04:39

I was also getting this error because the project imported main and test folders as modules. Click on Project --> Press F4 --> In Module settings, remove main and test folders and the make the project again. Problem will be resolved.

查看更多
成全新的幸福
5楼-- · 2019-01-08 04:39

To me the problem what that I had to check the box "Import maven projects automatically" under Setting> Maven>Importing

查看更多
姐就是有狂的资本
6楼-- · 2019-01-08 04:39

If you imported your maven project in IntelliJ and there are errors because of maven imports not getting resolved, it maybe because of the custom maven settings.xml you may be using. I tried overriding it in the Intellij default maven settings but it did not help. Finally I had to keep it in ~/.m2/settings.xml and then IntelliJ finally honored it.

查看更多
看我几分像从前
7楼-- · 2019-01-08 04:40
  1. close intelliJ
  2. open the same project
  3. when the project loads, at the lower right u can see a pop up saying "non managed pom.xml file found", if u click on it a new pop up will come, saying add maven project, click on it, and done.
查看更多
登录 后发表回答