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条回答
太酷不给撩
2楼-- · 2019-01-08 04:44

In Settings -> Maven -> Repositories only some repositories configured in my settings displayed.

Workaround

It is probably a bug (Idea 13.1.5 Ultimate). It helped me to switch the mirrors. The one that was not showing up to the top.

查看更多
干净又极端
3楼-- · 2019-01-08 04:44

Keep in mind that IntelliJ adds your local Maven installation's classes to its own classpath, so keep it up to date.

In my case IntelliJ tried to call method org.eclipse.aether.util.ConfigUtils.getFloat(). This caused a java.lang.NoSuchMethodError, because my years old Maven version didn't contain this method yet. Due to the exception IntelliJ stopped resolving dependencies.

After updating Maven, you have to change the "Maven home directory" setting in "Build, Execution, Deployment" -> "Maven". After that you must restart IntelliJ, because the classpath of IntelliJ's JVM won't change while running.

It took me some time to solve this problem, as I didn't expect IntelliJ to use the classes of my local Maven installation. I thought it uses it's own bundled JARs. So hopefully this information is helpful for others.

查看更多
乱世女痞
4楼-- · 2019-01-08 04:48

I have tried several options, but this one finally solved my problem. I re-imported the project by following these steps in IntelliJ:

  1. File -> New -> Project From Existing Repositories
  2. Choose your project from 'Select File or Directory to Import'

  3. In the next screen choose 'Import Project From external model', and choose 'Maven.

  4. In the next step, click the checkbox 'Import Maven projects automatically', (that solved my problem)
  5. Finish up by choosing profiles if necessary

For me re-importing maven projects did not solve the issue for an existing projects.

查看更多
神经病院院长
5楼-- · 2019-01-08 04:49

3 Simple Steps: IntelliJ 14:

  1. File>settings>Build,execution,deployment>Build tools

  2. Select Maven

  3. Maven home directory: C:/Program Files/apache-maven-3.3.3 (your equivalent location)

查看更多
Emotional °昔
6楼-- · 2019-01-08 04:50

It seems to me that solutions to this problem is plenty and all look a bit like magic. For me, invalidation of caches, re-importing or anything else already mentioned was not working. The only thing that helped was (without re-import) go to Maven settings, uncheck automatic importing and re-check it back.

enter image description here

查看更多
再贱就再见
7楼-- · 2019-01-08 04:54

I had the very same problem as author!

To solve my issue I had to add Maven Integration Plugin: File | Settings | Plugins

Like this:

Maven Integration Plugin

After that Intellij downloaded all the dependencies from pom.xml file.

Now if I want to create a project based on maven model, I just choose Open on the first Intellij window and choose the pom.xml file:

enter image description here

查看更多
登录 后发表回答