IntelliJ Maven Project defaults to incorrect dependency versions
Summary: I have multiple versions of several different libraries in my .m2 repository. My maven pom specifies to use a particular version of each dependency. My project builds properly from the command line (using mvn clean install). However, when I attempt to build or edit code within IntelliJ IDEA, my IDE defaults to use the oldest version of each dependency, instead of the versions for the dependencies which have been specified in the pom.
For example: in my .m2 directory I might have the following versions for dependency X: 2.1, 2.2, 2.3, 2.4. My pom specifies dependency version 2.3. However, the IntelliJ IDE defaults to using version 2.1. If I delete version 2.1 from my .m2 directory, the IntelliJ IDE will default to using version 2.2.
Deleting versions from my .m2 directory is not a solution in practice. For example, there is one project I work on daily which uses 2 different versions of the same dependency in different modules. Module A uses version 2.2, while module B uses version 2.3. In this case, I would expect IntelliJ to use version 2.2 while I edit/compile files in module A, and version 2.3 while I edit/compile files in module B. The actual behavior is that IntelliJ uses version 2.1 for both modules, which results in errors.
Temporary Manual Solution: The way that one can solve this problem is by going into File -> Project Structure -> Dependencies and manually removing the unwanted versions of the dependencies (by highlighting them and clicking the "-" button, and then clicking "apply").
However, this is only a temporary solution. Every time I import a new project, open an existing project, or even just switch git branches, all of the manual work I have done to get the correct versions of each dependency (by following the method above) is undone. Manually fixing this every time is untenable as I work with multiple git branches and also work on multiple different services, each of which use different versions of the library dependencies. Some dependencies which are regularly changed and updated produce 30+ jars. Manually removing all of these jars every time should not be the solution to this problem.
Re-importing the project and invalidating the cache are fixes that I have tried but which do not work.
This is a problem which has also been documented before (although not brought to a resolution) here
Expectation: IntelliJ should always resolve its dependencies deterministically based on what has been exactly specified in the pom file. If I change the pom file, then I would expect IntelliJ to use the newly specified version by default. As a user of IntelliJ, I expect this kind of dependency resolution to work seamlessly with little to no additional manual work, just as it does for build tools such as maven and gradle.
Build versions: I am using IntelliJ IDEA CE 2020.2 on MacOS Catalina 10.15.7
Please sign in to leave a comment.
Sounds like https://youtrack.jetbrains.com/issue/IDEA-255594 Could you attach idea.log (Help | Show Log in ... action) file after IDE restart and reproducing (and after calling a Reload action in Maven tool window).
Please try if enabling maven.always.remove.bad.entries option in Registry dialog (to open dialog use Help -> Find Action, type Registry) helps.
Please try also using different Maven and/or JVM in settings:
Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Maven home path
Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for importer.
For uploading you can use https://uploads.jetbrains.com or any file sharing service.
Thanks Andrey Dernov.
The following methods do not work for me, attempted both after re-importing the Maven project and attempting to Invalidate Caches/Restart.
I have an idea.log file. However, since it contains private information I am working on reproducing the issue at a smaller scale. If that doesn't work, I will try to obfuscate the class/package names which the log file contains. Is there any way to generate a log file which obfuscates class/package/module names by default?
>Are there recommended versions for the importer JDK and/or Maven?
Normally any JDK and Maven versions should work, provided that they are compatible. This is just a check if the problem may be caused by specific JDK or Maven installations.
>Is there any way to generate a log file which obfuscates class/package/module names by default?
There is no such an action unfortunately. I would just note that the files uploaded at https://uploads.jetbrains.com are visible only to JetBrains developers and are used only internally for the investigations.
Andrey Dernov I have uploaded my Idea log file:
Upload id: 2021_02_01_4ACLfcEJfGD6bf94 (file: idea v2.log)
I hope that we can get this resolved!
There are Maven syntax errors in pom.xml:
and
Please verify the structure of your pom.xml fil(s) and correct the configuration accordingly. The second problem I also mentioned here.
Thanks Andrey Dernov. After fixing these errors locally, I have verified that the dependency resolution issue still persists.
Regardless, these errors which are being logged are occurring in a separate child module of my full maven project. The other child modules do not log these errors, yet they still face the problem of IntelliJ incorrectly resolving maven dependencies.
The next 2021.1 EAP version will contain an important fix which could be related to this problem. Could you please try with this version when it is available at the 2021.EAP page or using Toolbox App. It should be already available this week (today or tomorrow).
If problem remains please attach several last idea.log files after issue has been reproduced. Thank you.
Andrey Dernov I would like to revise my earlier comment - after fixing the reporting plugins error the dependency resolution issue has been resolved. It seems like because of these errors in the pom file, IntelliJ was actually not reading the pom file, which led to IntelliJ being unable to detect updates to the pom file such as new dependency versions.
The question now becomes - why can't IntelliJ read the pom file even when these errors are present? This seems to be the root cause of the issue here. Maven, eclipse, STS, etc. are all able to read pom files in lieu of these errors.
Thank you for the update. Looks this issue https://youtrack.jetbrains.com/issue/IDEA-247186 / https://youtrack.jetbrains.com/issue/IDEA-258602 I've notified the team about your report.
Hi Andrey Dernov,
just wanted to let you know I was having the same issue as the thread starter and fixing the validation error also fixed the dependencies.
Thank you very much!