163

I just imported 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 are no exceptions in idea.log...

starball
  • 20,030
  • 7
  • 43
  • 238
Burst
  • 1,755
  • 2
  • 11
  • 7
  • IDEA version? Any related exceptions in [idea.log](http://intellij-support.jetbrains.com/entries/23352446)? Maven version? What OS do you use? Does Reimport button work in the `Maven Projects` tool window? Do you see the dependencies under the `External Libraries` node in the `Project View`? – CrazyCoder Mar 31 '13 at 07:43
  • 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. – Burst Mar 31 '13 at 07:47
  • there is no exceptions in idea.log... – Burst Mar 31 '13 at 08:01
  • Try [IDEA 12.1](http://confluence.jetbrains.com/display/IDEADEV/IDEA+12.1+EAP), enable **Maven 3** in `Settings` | `Maven` | `Importing`, network configuration [may also affect it](http://intellij-support.jetbrains.com/entries/23403071). – CrazyCoder Mar 31 '13 at 08:19
  • thanks for your answer, it works now, but there is still a problem: the dependencies which scope=system will not be deployed when run in tomcat. – Burst Apr 19 '13 at 14:20
  • Try changing the scope to `compile`, http://youtrack.jetbrains.com/issue/IDEA-70472 may be related. – CrazyCoder Apr 19 '13 at 14:26
  • See also http://stackoverflow.com/q/11454822/32453 this can be caused by "failures" in the pom.xml file at times... – rogerdpack Mar 03 '16 at 20:29

34 Answers34

158

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

Please note that idea plugin is retired

freedev
  • 25,946
  • 8
  • 108
  • 125
ranpengcoder
  • 1,597
  • 1
  • 9
  • 3
142

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.

MCP
  • 4,436
  • 12
  • 44
  • 53
  • 20
    This is good, but I also had to load the project as Maven project - choose File | Open, your pom.xml and wait. – MaKri Jul 18 '15 at 11:01
  • 3
    Both this answer and the first comment fixed my issue. Thanks guys! – miken.mkndev Feb 12 '16 at 09:44
  • I needed to increase the memory for the importer even further and finally went with -Xmx4096m (it is a big project). This is *different* from the memory settings in the idea.vmoptions! – Yasammez May 24 '16 at 09:00
  • Thanks, I had a problem where Maven 3.0.5 (bundled) would result in no maven dependencies being imported, but updating to use 3.3.9 allowed all the dependencies to import correctly. – Matthew Buckett Nov 28 '16 at 15:23
  • Not sure why IDEA doesn't have context menu similar to Eclipse to build maven based project. With version 2017.2 you need to do File > Other Settings > Default Settings > search for maven in search field. IDEA has really bad UX compared to Eclipse – vikramvi Aug 29 '17 at 13:32
  • "Automatically download" was critical for me, as was switching to a different network, since IntelliJ always battles my company's proxy server. Now I can stay on my company's regular network, and do my development work. (: – paultamalunas Oct 26 '17 at 22:32
48

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

Conor Svensson
  • 1,151
  • 11
  • 17
37

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.

Anurag
  • 843
  • 1
  • 9
  • 16
  • 1
    This also turned out to be my problem after importing an existing Maven project into IntelliJ 14.0.3 and selecting all the default options during the import process. – Nate R. Feb 16 '15 at 23:18
  • After hours of searching, this did the trick for me. BlessUp! – SourceVisor Oct 18 '15 at 03:43
  • This worked for me as well! Does anyone know why this breaks resolution? – dmi_ Feb 11 '16 at 19:05
  • This worked for me to, this is the easiest one I tried.. Thanks! – rrw Jul 01 '16 at 02:39
  • I've face the issue when importing Maven project from Netbeans. This has solved my issue. Thank you. – Nerzid Apr 15 '17 at 10:50
  • 1
    +1 ... this totally did the trick for me. Everything appeared to be set up fine, pom.xml was read, libraries present, but needed to do this to get errors to go away. – davesbrain Jun 19 '17 at 19:23
10

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.

caytekin
  • 171
  • 2
  • 12
7

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

Jarosław Jaryszew
  • 1,414
  • 1
  • 12
  • 13
6
  1. Close IntelliJ
  2. Open the same project
  3. When the project loads, at the lower right you can see a pop up saying non-managed pom.xml file found, if you click on it a new pop up will come, saying add as maven project, click on it, and done.
Negar Zamiri
  • 641
  • 2
  • 11
  • 16
5

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

Laura Liparulo
  • 2,849
  • 26
  • 27
  • Thanks! Still is an up-to-date solution for Intellij IDEA 2016. Maven importing allowed to open existing maven project seamlessly unlike a project opening which caused multiple dependency issues! – Exterminator13 Feb 22 '18 at 16:31
4

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.

vishal
  • 895
  • 1
  • 9
  • 25
4

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

Anatolii Stepaniuk
  • 2,585
  • 1
  • 18
  • 24
3

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

Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
2

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.

sdm
  • 1,236
  • 11
  • 9
2

try maven command shared below it would work!

mvn idea:idea
ibrahimgunes
  • 131
  • 8
1

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.

Amio.io
  • 20,677
  • 15
  • 82
  • 117
1

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.

Luka Hale
  • 31
  • 5
1

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

Martin D
  • 667
  • 1
  • 10
  • 25
1

In my case,i expanded the maven projects panel on the right side, clicked + and added the project. Then it worked.

Murat
  • 3,084
  • 37
  • 55
1

Okay I was facing this problem for days. Was trying to import POI library and Simple JSON library, I tried all the proposed answers and solution nothing worked. In the end the solution for my case was quite simple

I just needed to add the following to my module-info.java file after putting the dependencies in my POM file :

 requires poi.ooxml;
 requires poi;
 requires json.simple;

so I think because my project was in a package in a module I had to do this to let the system knows that these imported libraries will be used. so simple put the library name after require in your module-info.java file

Hope it works for you

Abdussalam
  • 11
  • 1
1

If you have any dependencies in pom.xml specific to your organisation than you need to update path of setting.xml for your project which is by default set to your user directory in Ubuntu : /home/user/.m2/settings.xml -> (change it to your apache-maven conf path)

Update Setting.xml file Intellij

Pukhraj soni
  • 1,832
  • 2
  • 17
  • 11
1

For me to sort this issue I had to go to Build, Execution, Deployment -> Build Tools -> Maven -> Importing and set JDK for import to JAVA_HOME! Then Reload all maven projects from the maven settings. All imports now work!!

sean le roy
  • 571
  • 1
  • 7
  • 19
1

If nothing works then you can just delete .idea directory and re-import the project :)

Vishal Maral
  • 1,279
  • 1
  • 10
  • 30
1

After a long trial and error, unchecking the pom.xml from ignore list worked for me.

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

Search and remove .iml file, it resolved the problem for me. Hope this helps someone.

Gaurav Wasan
  • 86
  • 1
  • 3
0

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)

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
zillani
  • 1,070
  • 3
  • 18
  • 26
0

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.

fishbone
  • 3,140
  • 2
  • 37
  • 50
0

<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

ycomp
  • 8,316
  • 19
  • 57
  • 95
0

there's an issue with the bundled Maven version. as someone previously suggested I switched to my own Maven installation and dependencies magically worked (IntelliJ 2018.3)

0

I have just had this issue when adding <dependency>...</dependency> elements to a <profile>. I just found that if I add (insert) the unresolved dependency elements to the <dependencies> element, the dependencies are downloaded from the maven repository; I can then remove the dependency element from the dependencies element.

JL_SO
  • 1,742
  • 1
  • 25
  • 38
0

Using default maven (which comes with IntelliJ) also could create this problem. So configure the maven which you have installed.

This can be done from: File -> Settings -> Build, Execution, Deployment -> Maven

Update following settings according to your maven installation:

  1. Maven home directory =
  2. User settings file =
  3. Local repository =
horizon7
  • 1,113
  • 14
  • 18
0

go to External libraries and remove them all libraries that says root after click on reimport all project

enter image description here

Andy Quiroz
  • 833
  • 7
  • 8
0

I tried all of the other suggestions in this thread and nothing worked - however I found this thread from the Jetbrains site and their solution did work for me. I hope it helps some of you as well. Specifically this suggestion worked:

  • Close the IDE
  • Delete the /Users/yourname/Library/Caches/IntelliJIdeaXXX/ directory (whatever your version is)
  • Start IDE and re-import project from scratch as Maven project

Worked like a charm for me, good luck! :wave:

btw I'm using IntelliJ IDEA Ultimate 2020.2 on a Mac.

Mark Madej
  • 1,752
  • 1
  • 14
  • 19
0

Unfortunately I ran into the same issue and I was head scratching why this is happening. I almost tried everything on this page and but none worked for me.

So , I tried to go the root of this problem; and the problem was (Atleast for me) that I was trying to open a maven project but pom file was not identified. So right clicking on the pom file and choosing "add as maven project" and then right clicking on the project -> Maven -> Reimport did all the magic for me :)

Hopefully this can be helpful for someone.

ajain
  • 444
  • 4
  • 7
0

Inside Intellij settings -> maven -> imports in the Use Maven3 to import project VM options for importer: -Xmx512m

This worked for me.

-1

You can go to your Maven directory(.m2) to delete all dependencies that have errors and show red, and then click refresh in Maven of IDEA. The error may be caused by incomplete downloading of dependencies due to network reasons

kfc966
  • 1