Output path populated with Maven repo paths
Answered
I'm seeing odd behavior, which I cannot reproduce reliably, where my project's output paths and test output paths get populated with paths from my local Maven repo instead of MODULE_DIR/target/[classes|test-classes]. When this happens, it affects all modules in my multi-module Maven project. The result is that every module's output gets compiled into these directories (output path and test output path respectively):
-
(my home dir)/.m2/repository/org/basepom/basepom-minimal/25/target/classes
-
(my home dir)/.m2/repository/org/basepom/basepom-minimal/25/target/test-classes
That's a mess because all the modules' output get thrown together and this can cause conflicts. Usually a Maven reimport/restart will clear this up, but I'd much rather this does not happen. Anybody know why IDEA's output paths would get corrupted with these weird paths?
Thanks.
Please sign in to leave a comment.
Hello,
We have similar issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-112405.
Do you face this problem with any maven project? Is it possible to provide pom.xml (you could attach it in comments to the issue on YouTrack). Also please attach idea.log ("Help | Show Log in...") after restarting IDE.
Wow, that's a really old issue. I think my difficulty is that I have no idea when or why this happens, so I can't catch idea.log while it is in the act of messing up the output paths. I may have to write a script that monitors the project.iml file to catch it in the act. I will try to follow up with that issue. Thanks.
You could put your project under local Git repository, so all changes to IDEA related files will be recorded.
In my case it looks like this IML file corruption coincides with an OOM condition while resolving Maven dependencies. I had a script that scans the IML file for this corruption every 3 seconds, and both times it picked up this OOM error. I've updated IDEA-112405 with the idea.log and other details.
Thanks! We'll check it.
Same problem here, on a JDK8-based project. (Newer-JDK projects work fine.) My co-worker found a workaround that worked for me. Mentioning here in case it helps anyone else:
Under 'Settings / Build, Execution, Deployment / Build Tools / Maven / Importing' set 'JDK for importer' to 17 (instead of my 'Project Default' that was 11 because 8 had stopped working at some point).
(After changing that, do a 'Reload All Maven Projects'.)
We have the same issue with IntelliJ IDEA 2023.2.3 and already had it with 2022.2.3 as well.
We also have a multi-module maven project with many modules and several levels. Sometimes all classes are compiled into a target folder of one of the common parents in the .m2 repository. So all classes are now loaded from there leading to all sorts of problems (ClassNotFoundException etc.). Finding the error is nearly impossible and it may take hours only to find that IJ messed up the output directory again.
Changing the ‘JDK for importer’ to 17 did not work for us, it still happens randomly. We don't know how to reproduce it. After a maven reload it works again.
Maybe you could add a detection whether the output directory is changed to the .m2 repository. In that case report an error so we are able to find the cause.
Thank you for reporting this!
Could you please share the details on how exactly you trigger the build when the issue occurs (Build Menu, Gutter Icons, Maven Run Configuration / Tool Window)?
Thank you for the fast reply!
I use the Build Menu “Build Project” (Ctrl-F9) to build the project.
Thank you for sharing the details!
Options from the Build Menu rely on IDEA's Native Build System. While it may provide some performance benefits, it may also result in discrepancies compared to Maven-native builds.
I would recommend using Maven-native options (Run Configurations / Tool Window).
Alternatively, you can keep using the Build Menu options, if you enable Delegate IDE build/run actions to maven.
So, you are saying we can choose between the IntelliJ build, which is fast but not reliable, and the Maven native build, which is slow but correct? Since the IntelliJ build works correctly most of the time, switching to the Maven build sounds like a workaround. However, we can try it out and check whether it really works better. Maybe it fails as well sometimes and it is not an IntelliJ bug after all but a Maven bug, who knows.
IDEA's Build System is reliable, but in some more complex cases it may produce the results that differ from Maven, as it uses slightly different build logic.
This particular case is a known issue, described in IDEA-112405.
We are currently looking for a reliable way to reproduce the issue, so it can be investigated and addressed.