81

I have a project in IntelliJ IDEA which was created with Maven. I then specified a set of dependencies and external repositories in the Pom.xml file.

The project builds fine on command line if I do mvn install. When I open any of the code files in the IDE though it says all the classes handled by Maven dependencies aren't recognized - as it would for a normal project if I never added the required JARs to the build path.

I know in my Eclipse Maven projects (rather than IntelliJ) it usually shows an extra directory on the left which says "Maven Dependencies" and lists the JARs pulled in via maven. I don't see that here. What am I doing wrong?


Here's what my screen looks like:

IDE Image

2240
  • 1,547
  • 2
  • 12
  • 30
John Humphreys
  • 37,047
  • 37
  • 155
  • 255

33 Answers33

77

Right click on the pom.xml -> Add as Maven project -> Reimport

Maven import

Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68
  • 4
    yeah would be nice if that worked, eh? but it doesn't, in 90% of the cases this bug happens. Which it does since years. Honestly im starting to believie JetBrains is incompetent. For years in a row this happenes to me and friends and colleagues. its a shame. – Gewure Dec 16 '20 at 02:54
  • 4
    works for me in IntelliJ IDEA 2020.2.2 (Ultimate Edition) Build #IU-202.7319.50, built on September 14, 2020 – David Abragimov Mar 05 '21 at 16:34
  • It works to me in IntelliJ IDEA 2021.3.3 (Community Edition) – Carlos Fernando Aug 25 '23 at 20:43
33

For some reason re-import did not do the trick. After looking at this:

http://www.jetbrains.com/idea/webhelp/maven-importing.html

I set auto-import and then the problem went away though; hopefully it helps someone else. Thanks for the ideas everyone :).

John Humphreys
  • 37,047
  • 37
  • 155
  • 255
  • 6
    I had selected auto import but it was failing for only one module alone. Then I found out that the module's pom.xml was selected in files to ignore under maven settings. Uncheck that and it worked. Hope this helps someone. (IntelliJ 14, btw) – Senthil Kumar Jan 08 '15 at 23:52
  • 1
    "I set auto-import". What does that mean? There are several settings that sound like this. What exactly did you set? – Stealth Rabbi Sep 11 '15 at 11:59
  • When you import a maven project it always asks with a bubble at the top right of the IDE if you would like to enable auto-import (in those words). I've done it on multiple computers and through many IntelliJ versions now, it's consistently there. That will make it start importing all missing maven dependencies as it finds them. – John Humphreys Sep 11 '15 at 16:37
32

After installing IntelliJ IDEA on a new computer I found myself with the same issue.

I had to update the remote maven repository. (Settings > Maven > Repositories)

enter image description here

Both local and remote repos needed to be updated. The remote one wasn't updated ever before this. After a restart everything worked fine. You might have to reimport your project.

Max
  • 904
  • 8
  • 15
  • 2
    After this update, restart was not enough, I had to re-import project to make it work. – Vulpo Feb 26 '15 at 16:01
26

You could go to:

File > Settings > Build, Execution, Deployment > Build Tools > Maven

and check if your pom.xml is not in the "Ignored Files" list.

approxiblue
  • 6,982
  • 16
  • 51
  • 59
Jarek
  • 381
  • 3
  • 7
  • 1
    i see my pom.xml in ignored list but how do i include back again ? – deeshank Jul 29 '16 at 13:26
  • 1
    Yep, that is what I found was my problem. How the heck that box got checked I have NO idea. It was not apparently checked before, then it got checked, and I had never visited that option screen before. It's like IntJ just decided to start setting its own settings. Haunted IDE? – Matt Campbell Sep 01 '17 at 19:27
  • Thank you. I had the same problem. I think if you're choosing to exclude the folder structure from git, Intellij will also exclude it from Maven. – kfkhalili Aug 20 '18 at 18:38
21

I was running into similar issues. For me it ended up being that I was importing the project incorrectly. I had been doing

import project
    <navigate to existing project and click top level directory>
    follow the wizard

What solved my maven problems was to do

import project
    <navigate to existing project and click the pom.xml
    follow the wizard
grinch
  • 804
  • 1
  • 9
  • 17
  • They guys at JetBrains claim to have fixed this issue with importing maven projects. They say that now if you select the top-level directory IntelliJ will notice it is a Maven project and import it correctly. Works for me in IJ 2018.3 – HairOfTheDog Mar 06 '19 at 22:54
16

For me File>>Invalidate Cache/Restart>>Invalidate and Restart worked in IntelliJ

Sherin Syriac
  • 447
  • 6
  • 13
6

Idea cannot download all dependent jar packages using maven,try the following operations:

mvn -U idea:idea

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

Vijay Godithi
  • 111
  • 1
  • 3
5

I've encountered a similar issue after refactoring my maven project into different modules. Re-importing on it's own usually doesn't work, but I've found that deleting the .iml files and then re-importing usually does the trick.

Michael Race
  • 51
  • 2
  • 1
  • JetBrains should be ashamed. This bug(s) are ongoing since years. – Gewure Dec 16 '20 at 02:55
  • Still true as per IntelliJ IDEA 2021.1.1. Quit IntelliJ, delete the `*.iml` files inside `.idea`, open IntelliJ again, and then run _rescan_ on the `pom.xml` file. – adib May 17 '21 at 07:00
4

A simple reimport and/or update of the repositories via Intellij did not do the trick for me.

Instead I had to delete the complete ~/.m2/repository directory and let maven sort everything out by itself. Afterwards Maven -> Reimport finished it off.

Matt
  • 116
  • 6
3

Ran into the "same" issue some days ago. It might not be related as my issue was more specific to Spring boot but as I was struggling with it and tried every solution on this post I'm going to share my experience.

What I was trying to do is to add one of my spring boot app into another project as a maven dependency. The dependency was resolved but I couldn't access my classes.

When no packaging is declared, Maven assumes the default packaging is JAR. The JAR generated by the Spring Boot Maven Plugin overrides the default one generated by Maven.

The solution was:

The solution that we found is to generate another JAR which will be used as a dependency to be imported from other projects.

The full article which helped me solve my issue.

Hope it helps someone.

Boggie
  • 29
  • 3
2

In my case the problem was that the project was in maven2 while intellj was configured for maven3. Switching to maven2 in settings solved the problem

2

Might be useful to others that were still stuck like me. None of the suggested fix worked. Actually, not before I fixed my main problem which was the installation location of maven.

In my case, I did not use the standard location. Changing that location in the maven settings (Settings/Maven/Maven home repository) did the trick.

My 2 cents.

mikey
  • 69
  • 3
2

For reasons I don't understand, in my case, I needed turn on setting "Always update snapshots" in Build, Executions, Deployment > Build Tools > Maven.

That made IntelliJ redownload dependencies and make it work.

Krešimir Nesek
  • 5,302
  • 4
  • 29
  • 56
2

Cache is causing problems! Make sure to do the following:

In your terminal, go to project/module:

mvn clean install

In your IntelliJ:

  1. File > Invalidate Caches > Invalidate

  2. Right click on project/module > Maven > Reimport

  • After spending so much time and trying every solution discussed, this worked for me. Thanks for sharing. – Khushboo Mar 06 '23 at 14:15
2

Worked for me:

mvn -U idea:idea

Since mvn -U updates the dependencies, check what mvn -U does: https://stackoverflow.com/a/26224957/6150881

Before this I have tried following steps but these have not helped:-

  1. Deleted .idea and .iml file
  2. Invalidate cache and restart
  3. Maven -> Reimport .
Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38
1

For my case I should have checked the work offline

Go to File>Settings >Build, Execution, Deployment >Build tools>Maven Then check Work Offline

1

This happened when I was upgrading from Java from 8 to 11 and Spring version. All the dependencies in the maven section disappeared as if no pom file existed. Was able to find the issue by doing

mvn clean

It showed me that one of the dependencies was missing version tag and it needed one.

<dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
</dependency>

After adding version to the above dependency it started showing up all the dependencies under maven section.

Dharman
  • 30,962
  • 25
  • 85
  • 135
anand
  • 166
  • 1
  • 10
1

This happened to me when I had mistakenly set my IntelliJ to power saving mode. Power Saving mode is displayed by battery icon with half empty charge. Disabling that fixed the problem.

0

This also happened to me after upgrading Intellij to 1.4.15. I tried to re-import the whole project with same result, but enabling Maven Auto Import did the tricks.

Eirik
  • 1
0

Looks like there are several, valid reasons why intelliJ would ignore a pom file. None of the previous answers worked in my case, so here's what did work, in case someone else runs into this issue:

In this example, module3 was being completely ignored by IntelliJ. The pom.xml in that directory wasn't even being treated as a maven pom.

My project structure is like this:

myProject
    module1
    module2
    module3

BUT, my (simplified) pom structure is like this:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>devs</groupId>
    <artifactId>myProject</artifactId>
    <version>0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>myProject</name>

    <modules>
        <module>module1</module>
        <module>module2</module>
    <modules>

    <profiles>
        <profile>
            <id>CompleteBuildProfile</id>
            <modules>
                <module>module3</module>
            </modules>
        </profile>
    </profiles>
</project>

To fix this, I modified the root <modules> element to add in module3 temporarily.

    <modules>
        <module>module1</module>
        <module>module2</module>
        <module>module3</module>
    <modules>

Next re-import the root pom, and IntelliJ will add the module. When that's done, revert the pom. IntelliJ will ask if you also want to remove module3 from the project structure. Click No.

Bam! Done. Module3 works and I can run my Integration tests from IntelliJ again :D

HankScorpio
  • 3,612
  • 15
  • 27
0

The problem was caused for me by selecting the project directory to be Imported when first starting IntelliJ rather than the pom.xml file for the project.

Closing the problem project and then following the Import process again but choosing the pom.xml resulted in a fully working project in the IDE.

nickebbitt
  • 1,711
  • 1
  • 13
  • 13
0

For me the problem seems to be a conflict with the maven helper plugin (https://plugins.jetbrains.com/plugin/7179?pr=idea).

I disable it, and it works again :)

fan
  • 2,234
  • 1
  • 23
  • 24
0

Go to File > Settings > Build, Execution, Deployment > Build Tools > Maven and check the Maven home directory. This should be the same maven installation used for command line

Akila
  • 187
  • 2
  • 9
0

For me, what did the trick was to add the dependencies in File > Project Settings > Modules > Dependencies.

hosford42
  • 376
  • 2
  • 16
  • it should add dependencies automatically, but it did not add, mvn install print build success but somehow Intellij Community does not add dependencies to classpath. – fuat Jul 29 '21 at 10:29
0

Just delete your project's .idea folder and re-import your project in IntelliJ.

gospodin
  • 1,133
  • 4
  • 22
  • 42
0

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)

Go to -> intellij settings -> build,Execution, Deployement -> Build Tools -> Maven -> User settings file

Update Setting.xml file Intellij

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

Restart, Invalid caches, outside building, none worked for me.

Only Reimport worked finally. For others sake, putting it as answer:

Right click the project > Maven > Reimport
KrishPrabakar
  • 2,824
  • 2
  • 31
  • 44
0

While importing a New project :

1.To identify all the modules in a project as maven modules: File --->New Project Settings -->Build Execution deployment -->build tools --> maven ---> importing ---> enable "search for projects recursively"

0

Option1: Right-click on the main project folder => Add Framework Support => Check Maven option

Option2: right-click on the pom.xml file and click on "Add as a maven project"

Ikbel
  • 1,817
  • 1
  • 17
  • 30
0

In my case the my maven home path was pointing to Bundled Maven 3 instead of where my .m2 folder was located, fixed it by going to File > Settings > Build, Execution and Deployment > Maven > Maven home path and adding C:/Program Files/apache-maven-3.5.4

Shay Ribera
  • 359
  • 4
  • 18
0

I have tried a lot of things and ended up adding the dependencies through the project settings>libraries section. If nothing else works it does the trick.

Pizza
  • 1
0

If you have multiple root projects open at the same time in your Projects window, try opening them separately in different Intellij windows.

This has helped me multiple times so far with projects having more advanced module structure (like hierarchical maven artifacts or multiple projects open at the same time).

Just choose the Open item from File menu and chose only on project or sub-module at a time.

msd.salehi
  • 839
  • 8
  • 14
0

for me mvnw.cmd and mvnw and wrapper cause the issue in intelliJ version:2021.3, I deleted them and just with pure pom.xml , file > project from existing source it worked

Ali.Mojtahed
  • 2,537
  • 1
  • 15
  • 23