Intellij can't find classes in same package


I am using Intellij Community and am having a strange issue.

If a class depends on a class in the same package the ide can't seem to find it.  The class is highlighted in red.  If I explicitly import it instead (I shouldn't have to for classes in the same package) the red goes away.  Building the project seems to be fine and produce no errors.

Anyone seen this before?


I've been dealing with this today as well. Invalidating cache and restart helped after doing it a couple of times. I was looking for some "sick" sources in the .iml files like was previously stated but i couldn't come up with a root cause. This also just happens on occasion. It will be fine for over a year and then it happens again. I don't recall if i had just updated when it cropped up again.

IJ version 2020.3.1 as well


Same to me. It occured several times now.

Invalidate Caches & Restart did not work for me.

Copied the unrcognized file to another name deleted the old and renamed the copy back to the original worked so far.

After a while it happened that serveral files where not recognized at the same time. So i killed IDEA, manually deleted all filess under .cache/Intelli*/cache/ and .cache/Intelli*/compile/ and restarted IDEA again. Takes a while but fixes the problem.

Quite annoying.

Unfortunately I can't provide any project to the public ...

Version Info:

IntelliJ IDEA 2020.3.2 (Ultimate Edition)
Build #IU-203.7148.57, built on January 26, 2021
Runtime version: amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Linux 5.4.0-65-generic

GC: ParNew, ConcurrentMarkSweep
Memory: 1937M
Cores: 8
Non-Bundled Plugins: com.alayouni.ansiHighlight,, com.intellij.ideolog, com.kondratevpavel.plugins.goland.gomethodgenerator, hunspell, org.jetbrains.plugins.go-template, CheckStyle-IDEA, PIT mutation testing Idea plugin, String Manipulation, com.chainstaysoftware.assertions2assertj, com.shankh.intellij.plugin.apache.eht, me.geso.assertj_postfix_plugin, Gitflow, org.sonarlint.idea, com.perl5, org.jetbrains.plugins.vue, aws.toolkit, org.asciidoctor.intellij.asciidoc, org.jetbrains.plugins.go
Current Desktop: KDE


Same problem with 2020.3.3. "Build > ..." just does not work (packages not found). While compiling via maven is successful. I can't provide logs, may be you tell where to look more? Cache invalidation does not help.


Ok, external package problem is localized. Just have to fix the problem with non-found classes of current module.

The problem is .idea/libraries is not refreshed after maven local repository field is updated (there is override checkbox enabled). there are tons of refs to jar://$USER_HOME$/.m2/repository... while i keep libraries in d:/work/.m2.

PS. Very strange. I do have -Duser.home in idea64.exe.vmoptions. So USER_HOME must refer to this folder. But non-found package was found only when i copied library info %userprofile%/.m2

PSS. I don't know how MAVEN_REPOSITORY variable (declared under Path Variables topic) is really used by IDE, but it referred at wrong location. I fixed it. And right now i can finally recompile test classes. But not the compile scope. Please, help! ))

PSSS. Oops, sorry. Right after removing junit from %userprofile%/.m2 repository recompiling test classes started to fail again. So i have no idea how to fix it. IDE just trying to grab deps form default folder, not actual one.

PS. After googling a bit have to add a note: my compiler excludes list is EMPTY.


>The problem is .idea/libraries is not refreshed after maven local repository field is updated (there is override checkbox enabled). there are tons of refs to jar://$USER_HOME$/.m2/repository... while i keep libraries in d:/work/.m2.

Looks like you were affected by the issue when MAVEN_REPOSITORY variable was lost in one of the IDE versions. The workaround is to re-define this macro variable explicitly in settings.

>PSS. I don't know how MAVEN_REPOSITORY variable (declared under Path Variables topic) is really used by IDE, but it referred at wrong location. I fixed it

It is used anywhere where the Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Local repository path is used in IDE settings files. By default (unles specified explicitly) it should be the <user home>/.m2 

Could you clarify what problem do you have at the moment? Please try if it helps to start IDE with defaults (File | Manage Settings | Restore Default Settings... action) and with IDE system directory deleted when IDE is not running.


> The workaround is to re-define this macro variable explicitly in settings.

Checked for MAVEN_REPOSITORY within path.macros.xml. It's already there. Right now i switched to "delegate to maven build"  in maven runner settings page as workaround. Sometime I'll try to delete system directory, but not now. Thanks for response, btw.


@Simon Logic what problem do you have currently?


I did "File -> Invalidate Cache/Restart" and it did work, but the issue is still a "thing" 

Mac OS Bis Sur 11.2.3
IntelliJ Ultimate 2020.3.1 build IU 203.6682.168


When this problem happens please provide some more information for the investigation.

1. Do you get errors only for classes from Maven libraries or for classes from other modules in the project?

2. Do you see "red" unresolved code in Editor for these classes?

3. Please provide the project project configuration files zipped (.idea project configuration sub-folder and module's .iml files) and IDE logs all zipped (Help | Collect Logs and Diagnostic Data action) after reproducing the build problem with build log debugging enabled (please see IntelliJ IDEA External Build logs section here ). Please also provide IDE config and system/external_build_system/ directories zipped.

For uploading, you can use or any file sharing service.


I would love to give full info but there are tons of corporate restrictions. I finally found the root of the problem. Every module compile output path ("Use module compile output path") for multimodule project was set to the same(!) folder somewhere in m2 repository. I removed .idea folder and all .iml files and reopened project from disk.


The latest IDEA 2021.2.2 for now, but the problem still exists - not seen classes even in one package. Invalidating cache and restarting and/or reimporting from Maven doesn't help at all.

The only what that really helped was exiting from IDEA, the complete removal of the directory <project_root>/.idea, and starting the IDE again with the project as a completely new one for the IDEA.


2022.3.1 here. The problem persists. Invalidating caches didn't help. Maven is not used in project at all, all libraries are local.

This happened to me a few weeks ago when IntelliJ had several crashes. The project is ancient, and his options didn't change over the years.

When I write a direct path to the class (class located in the same project and it is part of it, not a library) - after that IntelliJ is able to perform an import.

I am sorry, I cannot provide anything.



You may try to remove all IDE related data (.idea folder and .iml file) and reimport project again.


This happens with only a few classes so far, and after manual import, IDE starts to work normally with that class. This is what I can deal with without reconfiguring the whole project.

Thanks for the fast reply.


Thanks for information! Feel free to contact us if you need any assistance.


Kia ora! 

Several times in the past few days, my project, for (seemingly) no reason, IntelliJ thinks ClassA is inaccessible to ClassB at runtime. The class import remains valid, etc, even after IntelliJ throws the error. Once I rebuild (30-60 seconds), it's fine. It's just frustrating. 

Do we have a fix for this, yet? 




@Maclacjord Hi, what's your current IDEA version? Would it be possible to share a sample code of the `ClassA` and `ClassB` for checking?


Please sign in to leave a comment.