25

I've spent quite some time trying to figure out what I'm doing wrong and hoping someone may be able to help.

My current setup is running Maven 3.3.3 (via homebrew) and Java 1.8. IntelliJ 13 is the IDE of choice.

Running mvn -version results in the following:

Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-
22T12:57:37+01:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

which I believe means everything is OK, but when I go to my IDE and try to run a Maven project I get this error:

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -Dmaven.home=/usr/local/Cellar/maven/3.3.3/libexec -Dclassworlds.conf=/usr/local/Cellar/maven/3.3.3/libexec/bin/m2.conf -Didea.launcher.port=7539 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/local/Cellar/maven/3.3.3/libexec/boot/plexus-classworlds-2.5.2.jar:/Applications/IntelliJ IDEA 13.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.3
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
Process finished with exit code 1

My M2_HOME var is set to /usr/local/Cellar/maven/3.3.3/libexec, the same directory where homebrew installed it, and this also matches the IDE settings.

One search lead me to believe it may be something to do with Maven version and the IDE but I'm not convinced. Can someone please shed some light on this please?

2
  • 1
    I've added your answer as a community wiki below. In the future, if you've answered your question, please feel encouraged to answer it on your question.
    – Makoto
    May 7, 2015 at 16:06
  • Apparently tracked as IDEA-137783? But it seems to be a kind of regression in Maven, visible whenever you run for example M2_HOME=/…/apache-maven-3.3.3 /…/apache-maven-3.1.0/bin/mvn …. Oct 1, 2015 at 22:44

3 Answers 3

60

Just in case you have that error again go to Settings -> Maven -> Runner and add

-Dmaven.multiModuleProjectDirectory=$M2_HOME

to VM Options.

enter image description here

5
  • Hi, I still have the installation on intellij13 with the error so I'll try this when I get home. Thanks.
    – null
    May 7, 2015 at 16:07
  • This worked perfectly, thank you. I'll still use IDEA 14 because, new and shiny but I'm glad there was a sensible solution. :)
    – null
    May 8, 2015 at 6:12
  • 3
    I have a purchased license for IDEA 12, and the solution works for me also. Thanks. Oct 16, 2015 at 13:47
  • This may work, but it is not, what it should be. maven.multiModuleProjectDirectory property should point to the root of multi-module project, while M2_HOME is where Maven is installed. These are not the same thing. If it just needs to be set to anything, than you're fine. If it's used to locate some config files within the multi-project build, than you're not. Luckilly, mvn sets it, and IDEA 14+ does so as well. Maven, in general, has very loose (or lousy) definition of "root module" of your project.
    – virgo47
    Mar 2, 2020 at 21:06
  • If you are on Mac, go to IntelliJ > Preferences > Build, Execution, Deployment > Build Tools > Maven > Runner
    – SanjoS30
    Jul 8, 2022 at 0:30
7

I had this wired issue while trying to build CAS Overlay Template using Maven. I could resolve it by adding the following environment variable:

MAVEN_OPTS = -Dmaven.multiModuleProjectDirectory
1
  • export MAVEN_OPTS=-Dmaven.multiModuleProjectDirectory This worked for me
    – WarLord
    Sep 27, 2017 at 10:20
0

From the original question, the OP has solved their issue through this approach.

I upgraded to IDEA 14, imported settings, created a new Spring project and it worked out of the box.

1
  • Although this was my solution, the one above is the accepted answer for IDEA 13.1 - just in case someone else stumbles across this post but can't upgrade.
    – null
    May 8, 2015 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.