I am working on a Gradle project in IntelliJ and some packages are not recognized by IntelliJ. When I go to Project Structure -> Modules -> <my module> -> Dependencies, the jar file that contains these packages is there. (I've examined the jar file with jar tfv <file> to make sure that the classes in question are in the file.)
The classes in question are in red and when hovering over them, I get errors like "Cannot resolve symbol 'somepackagename'" or "Cannot resolve symbol 'SomeClassName'".
However, the gradle project compiles just fine from the command line.
I've tried all the existing suggestions I could find, but so far none have helped. Primarily, I've already tried:
Deleting the .idea folder and re-importing
Reimporting the project from the root build.gradle file
Clicking on the "Refresh all gradle projects" button
Upgrading IntelliJ
Clicking on "Invalidate Caches and Restart"
What can I do to get IntelliJ to recognize the packages in these jar files?
I also experience this problem on multi-project Gradle builds, it's still reproducible with the latest (at the moment of writing) IntellijIDEA 2020.3.2. It looks like some kind of internal caching issue, because even though IDEA complains it can't recognize the classes it can execute the build successfully.
Initially I was fixing it by invalidating caches and restarting IDEA, as had been suggested here, but then discovered that it goes away if I reload the project in Gradle Tool Window:
For me it works every time.
I had the same problem. My IntelliJ didn't recognize some dependencies from the build.gradle. My guess is that its a cache thing. So I did the following:
Delete the gradle caches directory.
rm -rf ~/.gradle/caches
Restart IntelliJ and refresh gradle dependencies.
This worked for me and seems like a simple solution.
I just had the same issue with Intellij Idea 2019.2.3 just after upgrading. Seems the File -> "Invalidate Caches and Restart" action fixed the problem.
Other previous actions I tried (reimport gradle project, remove .idea/* and .ipr/.iml, restart intellij) did not fix the issue.
The issue still occurs on IntelliJ IDEA 2021.3.2 (Community Edition). Invalidate Caches/Restart did not work, this solved it:
Delete the .idea folder
Close and open the project
In my case,
existing dependency lib deleting
gradle refresh!
ref link : https://youtu.be/0rLZK6hIpm0
You might have VPN enabled and this can cause the Gradle to stop importing dependencies.
This happened where my VPN connection was on and I was not able to import the dependencies.
Please check this as well if you are facing issues in addition to the solutions described here.
Also, check the proxy settings. Proxy might cause import problem we well. Try to disable the proxy and check.
IntelliJ IDEA 2017.2
I know this has been asked, but I have tried every fix I could find, as shown below.
Every symbol in my java code has an error Cannot resolve method, or Cannot resolve symbol. However, the code still compiles and runs with 0 errors. The error messages in the IDE started the first time I opened the project, on 3 separate computers, but runs fine on a fourth....I can't find anything different on that fourth computer.
I have following the following instructions from this issue:
File -> Invalidate Caches / Restart
I deleted the [IDEA system](https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs) directories, and re-imported the Maven project.
I have re-imported the Maven project
I re-imported the project with auto-import
I also followed the instructions from this issue:
File -> Synchronize
then
File -> Invalidate Caches / Restart
As well as the solutions here:
Check source roots
Ctrl+Alt+Shift+S
There were no errors or fixes in the Module source roots, or the module dependencies.
I also tried re-importing with "Search for projects recursively" checked as recommended here.
Edit1
This isn't a screenshot from my actual code, but my errors look the same as the screenshots from this post.
EDIT2
I just found an error I hadn't seen before. When I go to Project Structure (Ctrl+Alt+Shift+S), under Libraries, I see the following errors.
I checked on the location shown /home/user/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7-sources.jar and it doesn't exist. I have antlr-2.7.7.jar, but I'm not sure if I need to download the antlr-2.7.7.7-sources.jar, or just point my Library to the .jar I have (as I'm unfamiliar what these settings do)
The answer was the look through the pom.xml file line by line, and see what the dependencies were that I didn't have. I thought it was a configuration issue, but it wasn't.
I didn't notice that I didn't have the lombok plugin, which was a dependency for my project.
The problem listed in EDIT2 wasn't actually an issue since all of the classes were available.
Since your project compiles and runs successfully with mvn clean install, you know your pom is valid.
Given that, I would recommend to:
CloseIntelliJ
delete the .idea directory and any *.iml, *.ipr files for each of your modules. Don't worry, IntelliJ will re-create them. Back them up by renaming them if you're really concerned.
Open IntelliJ and find the new project wizard.
Find the option to import from an existing maven project
Select the pom for your root project
Check if module settings are correct. Open Project structure (Ctrl+Alt+Shift+S) and check the source directory settings under Source Tab are valid.
This is a weird one. I faced the same issue and went through all questions on stackoverflow and other forums and applied all suggestion to an extent to reinstalling intelliJ.
Though what problem in my case was that i had excluded some files namely .gradle and build folder, which definitely sounds important. I must have done this get excluded for git status notifs but somehow i had excluded it from my project as i am new to intellij. To check if any of your folders are exclude goto -> modules CTRL + Shift +Alt + s and check for any red items you should probably include the ones necessary here.
Hope this helps few of those out there.
you are using maven project, delete .m2 folder and update maven project and clean the project the rebuild it and run it... some time maven project occur that type of issue, which resolve by rebuilding the project. also check the version of your dependency.
I'm working on java 1.6 on eclipse. Yesterday, i tried to compile it to a runnable jar, but it didn't work.
So , finnaly i tried to change the java version and i still can't compile the project. Then i tried to convert my project to Maven.
Finally, i use this solution :
How do I remove Maven from a Eclipse java project?
But now, when i launch the project i have the error : 'Launching app' has encountered a problem. could not read maven project
in details i can read '...[FATAL] Non-readable-pom...' But i disable maven project.
And when i click ok, i can run my app, but i have a new pb what is 'the main class is not found'. I read on the net it's probably due to the java version changing.
Now, i'm looking to make the project as yesterday before those actions. I use git, so i tried to come back to the last commit but it doesn't work.
Could you give me some way or solutions?
ty, Olivier
This helped to me:
Exit Eclipse.
Delete the .metadata folder in your workspace.
Start Eclipse.
After that you can import all your projects import -> General -> existing project into eclipse. From root directory you can choose all your projects.
Had the same problem: I removed the maven aspect and the pom. The project ran fine until I restarted Eclipse the next day and got the "Non-readable-pom"
What fixed it for me was (1) edit the .classpath and remove all "pom-derived" annotations there (2) remove the m2e stuff from the .settings directory.
Had sameproblem: I figured the .. section in pom.xml was empty. Added 'groupId' and 'artifactId' there.Then in Eclipse:
Right click Project -> Maven -> 'Update Project'
It worked.
I am developing a maven project using IntelliJ-14. The other day everything was correct without any problem but today when I got in the project some of my imports are not working. When I compile it is everything ok and I can run the project but autocomplete does not work and some classes appear red.
I've tried to go File-> Settings-> Maven-> Importin-> Import Maven Projects Automatically check. Already imported the project again and nothing. In external libraries classes exist.
An example of my code is here.
What else can I do to solve this?
Please help
Right click on the project-->Maven--->UpadateProject.
This may help you.
Some possible solutions since we can't tell what is actually wrong:
Delete your .m2 folder and do a reload maven project
Go invalidate "caches and restart" (File - Invalidate caches /
Restart)
If you work with other people see if they have committed something that breaks the maven build. Some times the version of jars that you have in your local maven repo (.m2 folder in your %USER_HOME% folder) is different than the one that they other devs using
Do "Reimport all maven projects"
I experienced the same problem. Before it occured, I created a package structure from within IDEA, for example "de.ulli.myPackage". Of course I expected to get the directory structure "de/ulli/myPackage". I don't know why, but actually there was a single directory named "de.ulli.myPackage" (OS Windows 7 64 Bit). Maven was able to build the project, and I even could generate classes via IDEA. But autocomplete didn't work and the classes within the package appeared red in other sources. After reparing the directory structure, everything was fine.
I just imported a project from subversion to IntelliJ IDEA 11 - it's a maven project. But I have a problem in maven library dependencies so that I can't include all maven dependencies automatically - IDEA shows dependency errors only when I open that class/ Thats what I get here:
So I want all dependencies to be added automatically - is that possible or do I have to go through all class files to identify and add maven dependencies?!
UPDATE: After doing some modifications I found how to resolve my problem in some way. Thats what I did:
but I think logically it will not include and check new dependencies ahead?!... Is there any settings area for this in intelliJ - auto export dependencies to classpath?
IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.
When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.
You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".
If that doesn't help, then I would suggest to make a full clean-up and start again:
Close your project window (and IntelliJ) and remove all *.iml files and all .idea folders (there should be one per module)
Run mvn clean install from the command line
Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import
IntelliJ 2016 Update:
The Import Maven Projects automatically setting has been moved to Build, Execution, Deployment > Build Tools > Maven > Importing in your IntelliJ preferences.
Fix before IntelliJ 14
File [menu] -> Settings -> maven -> importing and uncheck "use maven3 to import project"
ref: http://youtrack.jetbrains.com/issue/IDEA-98425 (which may have a few other ideas too)
Fix IntelliJ 15+
Ran into this again, with IntelliJ 15 this time, which has no "use maven3 to import" option available anymore. The cause was that sometimes IntelliJ "doesn't parse maven dependencies right" and if it can't parse one of them right, it gives up on all of them, apparently. You can tell if this is the case by opening the maven projects tool window (View menu -> Tool Windows -> Maven Projects). Then expand one of your maven projects and its dependencies. If the dependencies are all underlined in red, "Houston, we have a problem".
You can actually see the real failure by mousing over the project name itself.
In my instance it said "Problems: No versions available for XXX" or "Failed to read descriptor for artifact org.xy.z" ref: https://youtrack.jetbrains.com/issue/IDEA-128846
and
https://youtrack.jetbrains.com/issue/IDEA-152555
It seems in this case I was dealing with a jar that didn't have an associated pom file (in our maven nexus repo, and also my local repository). If this is also your problem, "urrent work around: if you do not actually need to use classes from that jar in your own code (for instance a transitive maven dependency only), you can actually get away with commenting it out from the pom (temporarily), maven project reload, and then uncomment it. Somehow after that point IntelliJ "remembers" its old working dependencies. Adding a maven transitive exclude temporarily might also do it, if you're running into it from transitive chain of dependencies."
Another thing that might help is to use a "newer version" of maven than the bundled 3.0.5.
In order to set it up to use this as the default, close all your intellij windows, then open preferences -> build, execution and deployment -> build tools -> maven, and change the maven home directory, it should say "For default project" at the top when you adjust this, though you can adjust it for a particular project as well, as long as you "re import" after adjusting it.
Clear Caches
Deleting your intellij cache folders (windows: HOMEPATH/.{IntellijIdea,IdeaC}XXX linux ~/.IdeaIC15) and/or uninstalling and reinstalling IntelliJ itself. This can also be done by going to File [menu] -> Invalidate Caches / Restart.... Click invalidate and restart. This will reindex your whole project and solve many hard-to-trace issues with IntelliJ.
When importing the project, select pom.xml instead of the project directory. It should work.
Try to Re-Import the project from the Maven Projects panel in IntelliJ IDEA. It should download and configure all the dependencies defined in your pom.xml automatically.
If download doesn't work from IDEA for some reason, try mvn install from the command line and see if the dependencies can be fetched.
Of course all the required dependencies and any custom repositories must be defined directly in the pom.xml file.
For IntelliJ 2016-2.4 (and I believe other new-ish versions):
View > Tool Windows > Maven Projects
In the newly revealed toolbar, select Maven settings (icon of a toolset).
When this screen opens, expand the Maven menu and click 'Importing'
Here, click "Import Maven projects automatically." Also ensure that the 'JDK for Importer' option matches the JDK version you mean to use.
Click OK. Now go to the red dependency in your pom.xml, select the red lightbulb, and click 'Update Maven indices'.
What helped me:
Navigage:
Settings | Build, Execution, Deployment | Maven
Specify "Maven home directory" - the place you installed the maven
If certain maven modules are not compiling check if their pom.xml is on the "ignored files" list. In IntelliJ goto
preferences -> project settings -> maven -> ignored files
and check if the related pom.xml is ignored.
I had the same issue and tried all the answers mentioned here, none worked.
The simple solution is go to your project folder and delete all the .idea and .iml files and restart the IntelliJ ide. It works. No need to do anything with the settings.
Open IntelliJ Idea, Go to
File > Other Settings > Default Settings... > Maven (Preferences) > Importing or|
Preferences > Maven > Importing
Click on Enable Auto-import in the console.
When you create a new project you simply need to choose the option:
...
Import project from external model
Create IDEA project structure over existing external model (Eclipse, Maven...)
...
You'll find it pretty straight forward from there.
And in your case you can close your project and simply create a new one. Choose your project's directory, which will override it, making it a Maven project.
Importing Maven dependencies may not work if you import the same path several times. This may happen automatically after importing an existing maven project. I can't figure out why this happens, so I'm inclined to think it is a bug.
For example, if my project is
hibernate
src/main
src/test
the three paths may be imported as top nodes:
hibernate
src/main
src/test
If such is the case, the dependencies appear to be right, but they won't be used until you remove the superfluous paths (in this case, src/main and src/test). Once you do this, refresh and click Build > Rebuild Project. IDEA will pick up the dependencies.
A symptom of this problem is that IDEA warns you of a duplicated path when you manually check a library (second screenshot in the question).
There are several ways to re-read the dependencies in case you need it. If you go to the “Maven Projects” tab, there is a “Reimport All Maven Projects” icon at the top left of the tab. If you suspect IDEA became confused you can click on File > Invalidate Caches.
First check path Specified for User Settings file: in Settings -> Build,Execution,Development -> Build Tools -> Maven .
The field should have path of the settings.xml of your maven. Also the settings.xml should have correct path of remote repository.
Go into your project structure, under project Settings, Modules, select the dependencies table. For each dependency, change the scope from 'Test' to 'Compile'.
If in the lower right corner it says "2 processes running..." or similar, you may just need to wait for that to finish, since it may take time to download all the jars.
Reimport the project. If you install maven plugin you can use this.
Right click on the project -> Maven -> Reimport
I had a similar issue, in my case I am using a custom settings.xml which was not picked from IntelliJ.
Solution:
File > Settings > Build, Execution, Deployment > Maven: User settings file (chose here my custom settings.xml).
IntelliJ 2020.3.3
This one did it for me.
Build, Execution, Deployment > Build Tools.
Change "Reload project after changes in the build scripts":
from default "External Changes" to "Any Changes"
With this, it took a while for the project to rebuild but now I can see Maven dependencies in IntelliJ:
I ran into the problem that some subdependencies couldn't be resolved in IntelliJ 2016.3.X. This could be fixed by changing the Maven home directory in Settings > Build, Execution, Deployment > Build Tools > Maven from Bundled (Maven 3) to /usr/share/maven.
After that all subdependencies got resolved as in previous IntelliJ versions.
In my case, path for JAVA used by MAVEN was not set as JAVA_HOME as configured on the machine. Hence, it was not even trying to download the dependencies.
Steps I followed which solved this issue,
Checked for JAVA path , Settings >> Build >> Build Tools >> Importing >> JDK for importer. Pointed it to JAVA_HOME.
mvn clean install -U
Used above command to force the dependencies download.
Re imported Maven Projects
So I was also facing this problem in lots of my organisation's codebase. On addition to the answers suggested above, we can tweak around with the allocation pool memory of the jvm. This is because, the volume of the dependencies brought in large codebases may be overwhelming for the jvm for IDE to build the project completely. Hence tried increasing XMX value and it worked! Added -Xmx3072 to resolve the issue of "not building" my Java project in IntelliJ
Maven - Reimport did not work for me.
I have Spring project in STS(Eclipse) and my solution is to import project to IDEA like so:
1) File - New - Project from Existing Sources... - select directory - choose Eclipse.
2) Set Maven autoimport to true in settings.
3) Then right click in pom.xml and choose Add as Maven Project.
After this it has imported everything.
I had the similar issue with my macbook, just did a small change in pom.xml and it started downloading all dependencies:
Earlier dependencies were written as below for my windows machine:
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
I just removed the <dependencies> and </dependencies> tags and it started downloading all the dependencies:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
I am not sure it will work for you or not.. but worked fine for me.
Thanks
Deleting the .idea folder from the project directory, and then re-importing the project as a Maven project is what worked for me.
Invalidate Caches worked for me:
File > Invalidate Caches
Checks:
Clear file system cache and Local History
Clear downloaded shared indexes
Then Invalidate and Restart
I solved this issue by updating my settings.xml file with correct mirror config, seems that intellij will try to download meta-data from repository every time the maven module imported.
Hijacking a bit to add what ended up working for me:
Go into the Maven Projects sidebar on the right edge of the IDE, and verify that your dependencies are listed correctly under your module there. Assuming they are, just ask IDEA to reimport then (the first button at the top, looks like two blue arrows forming a counter-clockwise circle).
Once I did that, and let IDEA reload the project for me, all my dependencies were magically understood.
For reference: this was with IDEA 13.1.2
I faced the same problem and tried everything suggested which did not solve the issue, I was using Intellij version 13.1.3
Finally after spending more than couple of hours trying to fix it, I decided to try an upgraded version and opened the project in version 14.1.4 which ultimately resolved the issue. I would think this as a probable bug in the previous version.
I hope this helps!
I was able to resolve it by removing unnecessary modules from Project Settings -> Modules list.
It turns out these additional modules were created automatically by IntelliJ IDEA when I created the IntelliJ project by importing from the project folder (instead of by opening pom.xml). Then, after declaring the project as Maven project, proper modules were created, and existing modules were conflicting with them. It is also possible to exclude those modules during project creation.
In my case, one of the modules was ignored for some reason.
To resolve that: Right click the problematic module and choose "Unignore Projects".
You might be working under a company's internal network.
If so, to download or add external Maven dependencies your settings.xml file under user/<username>/.m2 folder might need to be updated.
Contact your administrator to provide the right settings.xml file and then paste it into you .m2 folder.