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条回答
Bombasti
2楼-- · 2019-01-08 04:57

I was getting this error because my project was not setup correctly. It had imported main and test folders as modules. When I deleted the 2 modules (but retained them as source and test folders), my code started compiling correctly.

查看更多
一夜七次
3楼-- · 2019-01-08 04:59

I have encountered this problem,idea cannot download all dependent jar packages using maven,i just tried the following operations:

 mvn -U idea:idea

then all the dependent jar packages are download from the maven repository

查看更多
地球回转人心会变
4楼-- · 2019-01-08 05:01

I ran into this issue when using IntelliJ 14's bundled Maven 3 instance.

I switched to using my own local Maven instance, via:

Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Maven Home Directory

Then added the path to my locally installed instance.enter image description here

This got the dependencies to magically appear.

enter image description here

查看更多
仙女界的扛把子
5楼-- · 2019-01-08 05:01

With intelliJ 16.1.4 I had the same issue. You should have a look at the Event Log, because it told me "Non-managed pom.xml file found:..." I then clicked on it and the problem was solved.

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-08 05:01

<option name="workOffline" value="true" /> in workspace.xml is not your friend. Advise to check this before deleting your .idea (which has a lot of useful settings you probably don't want to lose)

It's a maven workspace.xml setting

查看更多
smile是对你的礼貌
7楼-- · 2019-01-08 05:02

I had empty settings.xml file in Users/.../.m2/settings.xml. When i added

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">

</settings>

all dependicies were loaded

查看更多
登录 后发表回答