Intellij can't find classes in same package

Answered

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?

41 comments
Comment actions Permalink

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

0
Comment actions Permalink

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: 11.0.9.1+11-b1145.77 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.cn.oddcn.plugin.gobuildergenerator, 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

0
Comment actions Permalink

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.

0
Comment actions Permalink

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.

0
Comment actions Permalink

>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 https://youtrack.jetbrains.com/issue/IDEA-239124 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.

0
Comment actions Permalink

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

0
Comment actions Permalink

@Simon Logic what problem do you have currently?

0
Comment actions Permalink

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

0
Comment actions Permalink

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 https://intellij-support.jetbrains.com/hc/en-us/articles/207241085 ). Please also provide IDE config and system/external_build_system/ directories zipped.

For uploading, you can use https://uploads.jetbrains.com or any file sharing service.

0
Comment actions Permalink

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.

1
Comment actions Permalink

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.

0

Please sign in to leave a comment.