Maven Dependency not recognized by IntelliJ

Answered

Hello,

I've been struggling for a few hours on a dependency problem on my maven project. As I'm trying to debug my program, I'm using IntelliJ built in functionality.

Unfortunately it doesn't work. My IntelliJ wouldn't recognize the following dependency :

java: package org.junit.jupiter.api does not exist

Here is my pom.xml dependencies

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

The output

java: package org.junit.jupiter.api does not exist

is appearing when I'm importing this in my tests : 

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
Obviously I tried running it using a terminal and it works properly, through mvn clean install, build, etc... I also tried the maven built in window in IntelliJ and it works properly.

It also works properly on my GitHub workflow, it even update my CodeCov badge and shows the percentage as expected.

 

I really tried everything on IntelliJ, from reloading the maven project, to reimporting the project using the pom.xml or even Invalidate caches -> Clear file system cache and local history

 

I hope someone will be able to help me, have a good day.

1
27 comments

If you haven't already please try following:

  • Unlink maven project, re-add it and reload maven project from the maven tool window: https://i.imgur.com/2bVzAuf.gif
  • Check if pom.xml file is not added in the ignored files list in Settings (⌘ + , or Ctrl + Alt + S) > Build, Execution, Deployment > Build Tools > Maven > Ignored Files
  • Delete the .idea folder and any *.iml files in your project folder and re-import the project from sources

If the issue persists, please share a screenshot of the entire IDE window showing:

  • Project tool window with External Libraries node expanded
  • Maven tool window with Dependencies node expanded

Also, if possible please provide a sample project for reproduction and your IDE logs (Help > Collect Logs and Diagnostic Data).
You can zip the files and upload them securely here: https://uploads.jetbrains.com, just provide the uploaded file ID. Thanks!

7

Thank you for your answer, I ended up deleting the whole project and re-pulled it from my GitHub repo and it worked perfectly fine.

I didn't think about deleting the idea folder and iml files, but it does sound like something that would have been better than just re-pulling the whole project ahah...

Have a good day !

0

After going crazy for a few hours, the trick was one of:

- "repair ide"

- "unlink and re-import as maven project"

-"remove all /.idea and start again from fresh import"

Very annoying, these things have happened before and really hard to debug where the issue is, as command line maven works as expected.

3

Unfortunately I have a similar (same?) problem and steps listed above don't help:

mvn clean install works
source code editor does let me drill down into org.junit.jupiter.api
running any test class shows:
"java: package org.junit.jupiter.api does not exist"

Other projects build in the same manner do work without issues.

Screenshots of the dependencies (project and maven) included.

A sample project is not possible - as I wrote I have problems with a specific project.

0

I have just deleted the project physically from the local file system, cloned it again, imported into IDEA and it works now.
Invalidating caches, reparing IDE, unlinking and linking Maven did not help.
Removing .idea subdirectory didn't help.
Only physically removing the project did help.

1

Did you check the ignored packages in the auto import settings?

0

This took me so long to fix that I had to take the extra time to comment on this thread. Only physically removing it and reimporting from github worked for me as well.

Invalidating caches, reparing IDE, unlinking and linking Maven did not help.
Removing .idea subdirectory didn't help.

0

In my case I had to specifically configure to the maven compiler plugin the source and target Java version. Example: 

<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>

0

Try to download sources, it worked out for me:

right click pom > maven > download sources

and then reload and recompile project

0

An update to my previous comment. My problem was that the parent Pom had release as a version. The new IntelliJ comes with maven 3.9 which treats it as an error and does not download the dependencies. To overcome it I had to set the maven to an older version (example 3.6) from the setting menu. 

0

Typically, if Maven processes a dependency correctly, but IDEA does not, that indicates a de-sync between Maven's and IDEA's Project Models.

In most cases this de-sync can be ironed out by running a Maven Sync:

Unfortunately, if de-sync is significant or IDEA's Project Model is corrupted, it has to be fully reset.

To do so:

  1. Close all instances of IDEA
  2. Rename or remove the System Directory
  3. Re-import the Project: Open → Navigate to Project's directory → Double-click the root pom.xml → Open as Project

If the issue persists, it's best to report it by submitting a YouTrack Issue or a Support Ticket.

2

Hello Roman Vatagin 

These last days, I was going through the same issue, in my case running the below maven command into an IntelliJ terminal fixed the dependencies desync:

mvn versions:resolve-ranges -DprocessDependencies=false  

0

Ivan Y Avila Thank you for reporting this!

Note that the latest version of IDEA (2024.3) provides the “Reload” option, that should allow you avoid running the Goal via command line:

I would also appreciate if you could share more details about the specific changes that the Sync is not picking up.

Once I'll be able to reproduce the issue, I can send it to the developers to get it addressed.

0

This is crazy still happening. 

I am adding a dependency, and dependency is listed in project structure but the file reference looks red, although file actually exists.

Reloading all maven projects is not fixing it. Repairing ide and rescanning project indexes fixes it sometimes.

I am considering switching back to Eclipse just because of this!

0

Serkan Erdur Could you please share more details about how the dependency is declared and the Project's structure?

When the issue occurs is the dependency listed under Project Tool Window → External Libraries?

As a workaround try the following:

  1. Close all instances of IDEA
  2. Rename or remove the System Directory
  3. Re-import the Project: Open → Navigate to the Project's directory → Double-click the root pom.xml → Open as Project
0

I think I found a workaround and have more idea how to reproduce it.

To reproduce:

1. Add a dependency to pom but dependency should not be in the local maven repository at that time

2. Click “reload all maven projects incrementally” button. 

Workaround solution:

After adding the dependency run a maven compile before clicking “reload all maven projects incrementally” button. Manual compile will make dependency downloaded to local repository hence the issue will not happen.

0

Serkan Erdur Thank you for sharing the details!

The issue, however, does not seem to reproduce in my environment.

Could you confirm you are using the latest version of IDEA (2024.3.2.2)?

Does the issue reproduce consistently for you?

Could you please share the IDEA logs?

0

I am using 2024.2.3 and cannot update it myself, version is managed by my company.

I could reproduce it last 2 times I tried.

0

Serkan Erdur I've tested with the 2024.2.5 - I'm not seeing the issue either.

Would you be able to share the affected Project or its POM(s) (preserving the directory structure) for further investigation?

0

Similar problem with

IntelliJ IDEA 2024.3.2.2 (Ultimate Edition)
Build #IU-243.23654.189, built on January 29, 2025
 

Build ok on maven but fail in IntelliJ with package not found. I added the project with the missing package as module but the error persists.

0

Could please try the following and let me know if it has any affect on the issue?

  1. Open IDEA
  2. Press Shift twice
  3. Type “Registry” in the Search Everywhere window
  4. Look up and enable the maven.sync.refresh.resolved.artifacts key
  5. Restart IDEA
1

Enabling maven.sync.refresh.resolved.artifacts seems to fixed my issue!

0

Serkan Erdur In such case, this is likely the issue described in IDEA-358024.

Fix for it has already been developed and will be available in both upcoming version of IDEA (2025.1) and via an update for 2024.3.

0

I do not think it is the same issue because this is not how it behaves for me. For me old dep is gone and, new dep does not appear.
"Actual result: The old dependency remains in the "External Libraries" view."

0

Serkan Erdur If the maven.sync.refresh.resolved.artifacts Registry Key helped - this is most likely the same issue.

The symptoms may be a little different, but the root cause if likely the same.

0

In my case maven.sync.refresh.resolved.artifacts was checked. It looks like it is working fine now after some ‘repair IDE’ and restarts. Sorry but I don't know exactly the moment it started to working fine.

0

Walter Mourao Let's keep monitoring the situation!

Let me know if the issue comes back at any point - if it does, we can investigate it further.

0

Please sign in to leave a comment.