Incorrect value for maven property multiModuleProjectDirectory
I have a multi-module project where I am using multiModuleProjectDirectory to refer to the path of the parent module in child modules.
Everything works fine when I build the project using mvn command line but when building in IntelliJ with option “Delegate IDE build/run actions to Maven” the project fails to build amd multiModuleProjectDirectory is resolved to my home directory instead of the project.
I can see that the java process that IntelliJ creates to build has the argument -Dmaven.multiModuleProjectDirectory=/home/username
I found this post from a year ago with a similar issue, and the workaround that was suggested then also works for me but this is not ideal as every developer on the project would need to customize their .mvn/jvm.config file
Also everything was working fine for me before and I think this might be a regression since I upgraded to IntelliJ IDEA 2024.1.3 Ultimate Edition.
Is this a known bug?
请先登录再写评论。
Hello, Francois-Xavier!
Thank you for reporting this!
The issue seems to be similar to IDEA-242198.
Could you please share more details about how you trigger the build (Maven Tool Window, Build Menu, Gutter Icons) and how
multiModuleProjectDirectory
is defined in your Project?Also, could you please let me know which version of IDEA you have upgraded from?
Hi Roman,
I have created a small project that reproduces the issue (more details on how to reproduce in the readme).
The project builds without error using mvn compile command
The build fails when I build from IntelliJ build menu or in the maven tool window when executing compile phase on the parent module, but if I execute compile phase on the submodule it succeeds.
I am not sure which version I had before but I think I updated not too long ago (maybe 2-3 months).
One of my colleagues who is on version 2024.1.2 cannot reproduce the issue while another one who is on the same version as me has the same issue.
Thank you for sharing the Project!
Interestingly enough, the issue does not seem to occur in my environment and the error message I'm seeing on the screenshots posted on the GitHub makes me think that this is the issue described in IDEA-334183 / IJPL-1055 (it may also affect Maven and other Unix-based systems like macOS).
Could you please let me know if starting IDEA directly from the OS Terminal using
idea
command helps with the issue in your environment?Starting from the terminal does not change anything.
I don't think this is a maven issue or related to environment variable. I have tried adding -XshowSettings:properties in the VM Options and it appears that IntelliJ is setting maven.multiModuleProjectDirectory with the incorrect value when creating the java maven process.
This is very curious!
I've done some testing on both Windows and macOS and still have not been able to reproduce this behavior.
I'm assuming you are using the default bundled Maven? Can you try switching to a Wrapper or a locally installed version and let me know if it has any effect on the issue?
Also, could you please try running the build with
-X
flag and share the output?I have tried with a locally installed version or the wrapper but the result is the same. The problem does not come from the maven version used but from the java command issued by IntelliJ when building the project. Here is the command when I try “Build/Rebuild project” from the menu:
/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/fbonnet -Djansi.passthrough=true -Xmx8g -Xms512m -Dmaven.home=/Users/fbonnet/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/maven/lib/maven3 -Dclassworlds.conf=/Users/fbonnet/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/maven/lib/maven3/bin/m2.conf -Dmaven.ext.class.path=/Users/fbonnet/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/maven/lib/maven-event-listener.jar -Dfile.encoding=UTF-8 -classpath /Users/fbonnet/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds.license:/Users/fbonnet/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.7.0.jar org.codehaus.classworlds.Launcher -Didea.version=2024.1.3 --errors clean install --projects com.atlassian.jira:multimoduleprojectdirectory-test,com.atlassian.jira:submodule
Note the
-Dmaven.multiModuleProjectDirectory=/Users/fbonnet
which is the cause of the problem. IntelliJ should instead set this property to the root of the project.When using
mvn clean install
instead of building in IntelliJ, if you look at the source code ofmvn
command, there is a function that traverses directory structure from process work directory to filesystem root, first directory with .mvn subdirectory is considered project base directory.IntelliJ should set the property the same way as mvn command
Something I forgot to mention is that I have installed IntelliJ using Jetbrain Toolbox. Not sure it makes a difference though.
Thank you for the update!
IDEA uses rather complex logic to determine the value of the
multiModuleProjectDirectory
, that it sends to Maven.Does this affect all Maven-based Projects in your environment or only specific ones (ones, stored in your Home Directory, for instance)?
Do you have multiple Maven Project linked ("+" icon on the Maven Tool Window)?
Would you be able to share more details about your computer's file system (volume structure, symlinks, etc.)?
Exact same situation here :/
For what I'm experiencing right now, IDEA 2024.2 EAP works better : while hitting Maven refresh there is a little stuttering and that's it.
I saw this stack in logs though :
I think I found the problem. I had a
.mvn
directory in my home directory, removing it solved the issue.I might have created this directory by mistake at some point.
Roman Vatagin where can I find the code that is used by IDEA to find the value of the
multiModuleProjectDirectory
(or some documentation)? In any case it should behave the same as when using directly mavenAfer a quick check I only have a `~/.m2` but no `~/.mvn` folder.
Sylvain Daclin Could you please share more details about your environment (OS, file system, Project Structure, Maven version and configuration)?
@Francois-xavier Bonnet I'm afraid, I may not be able to point to a specific part of code, where IDEA determines the
multiModuleProjectDirectory
value, but, according to the developers, it should follow Maven's original workflow, as described here.Obviously it does not follow exactly Maven's original workflow otherwise I wouldn't have had this issue.
@Francois-xavier Bonnet This might have been a unique case, that definitely deserves attention.
You mentioned removing
.mvn
folder from the home directory resolved the issue - do you still have the access to it's contents? Would you be able to share them for the investigation or let me know what files did it contain?I ran into what appears to be the same issue. My $HOME/.mvn was almost empty (one file, but that was empty). I'm trying to remove it and see if it fixes the problem.
💁♂️ jefschan/
› find .mvn
.mvn
.mvn/maven.config
💁♂️ jefschan/
› cat .mvn/maven.config
💁♂️ jefschan/
› rm -rf .mvn
Schangj09 Thank you for reporting this!
Let me know if removing the directory helps - if possible, please preserve its original contents.