Burst
Burst

Reputation: 1844

Intellij idea cannot resolve anything in maven

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...

Upvotes: 172

Views: 297011

Answers (30)

Hard Worker
Hard Worker

Reputation: 1111

I had to do something similar

  1. delete the .idea directory when project is closed
  2. dont use open instead do: File> new > project form existing source
  3. first I had to delete and redownload java sdk select the sdk on inteliJ setting
  4. mvn -U idea:idea
  5. settings > Build Exec > Build tools > maven imports > import > from below select the JDK maven is using.
  6. on maven tab
  7. Add maven projects select the module failing to compile.

Upvotes: 1

Mayank Padia
Mayank Padia

Reputation: 1

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

This worked for me.

Upvotes: 0

kfc966
kfc966

Reputation: 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

Upvotes: -1

Gaurav Wasan
Gaurav Wasan

Reputation: 86

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

Upvotes: 1

ranpengcoder
ranpengcoder

Reputation: 1637

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

Upvotes: 162

Sravan Gajula
Sravan Gajula

Reputation: 9

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

enter image description here

Upvotes: 1

Vishal Maral
Vishal Maral

Reputation: 1318

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

Upvotes: 1

sean le roy
sean le roy

Reputation: 567

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!!

Upvotes: 1

ajain
ajain

Reputation: 510

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.

Upvotes: 0

ibrahimgunes
ibrahimgunes

Reputation: 138

try maven command shared below it would work!

mvn idea:idea

Upvotes: 2

Mark Madej
Mark Madej

Reputation: 1912

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.

Upvotes: 1

hulesh chandra
hulesh chandra

Reputation: 71

  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.

Upvotes: 6

Andy Quiroz
Andy Quiroz

Reputation: 901

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

enter image description here

Upvotes: 0

Pukhraj soni
Pukhraj soni

Reputation: 2140

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

Upvotes: 1

Abdussalam
Abdussalam

Reputation: 11

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

Upvotes: 1

horizon7
horizon7

Reputation: 1293

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 =

Upvotes: 0

JL_SO
JL_SO

Reputation: 1901

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.

Upvotes: 0

Murat
Murat

Reputation: 3284

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

Upvotes: 1

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)

Upvotes: 0

Martin D
Martin D

Reputation: 697

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

Upvotes: 1

Valeriy K.
Valeriy K.

Reputation: 2906

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

Upvotes: 4

ycomp
ycomp

Reputation: 8563

<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

Upvotes: 0

fishbone
fishbone

Reputation: 3249

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.

Upvotes: 0

Luka Hale
Luka Hale

Reputation: 31

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.

Upvotes: 1

caytekin
caytekin

Reputation: 171

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.

Upvotes: 10

zillani
zillani

Reputation: 1090

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)

Upvotes: 0

sdm
sdm

Reputation: 1246

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.

Upvotes: 2

Conor Svensson
Conor Svensson

Reputation: 1251

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

Upvotes: 53

Anatolii Stepaniuk
Anatolii Stepaniuk

Reputation: 2703

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

Upvotes: 4

Jarosław Jaryszew
Jarosław Jaryszew

Reputation: 1492

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

Upvotes: 7

Related Questions