Travis Nelson
Travis Nelson

Reputation: 2620

Maven home (M2_HOME) not being picked up by IntelliJ IDEA

I am trying to do a simple maven build with IntelliJ IDEA 10.5.1 on OS X Lion and am getting the following error:

Error running my-app [package]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.

I have set M2_HOME to the following, but I am still having issues. And yes, I did restart IntelliJ.

$ echo $M2_HOME
/usr/share/maven

I then manually entered the path to maven in IntelliJ's Maven Settings for the project. This is not something that I want to do for every project, so is there something I am missing with how to get IntelliJ know where my maven home is?

Upvotes: 50

Views: 157720

Answers (8)

Silvio Corso
Silvio Corso

Reputation: 1

This might not be the right place, but I wanted to mention that I had an issue with IntelliJ not recognizing the POM files of my projects. I initially thought it was a bad Maven configuration. Instead, I just needed to right-click on the root directory and select "Mark Directory as -> Sources Root."

Upvotes: 0

user5202836
user5202836

Reputation: 71

If M2_HOME is configured to point to the Maven home directory then:

  1. Go to File -> Settings
  2. Search for Maven
  3. Select Runner
  4. Insert in the field VM Options the following string:

    Dmaven.multiModuleProjectDirectory=$M2_HOME
    

Click Apply and OK

Upvotes: 7

flutesa
flutesa

Reputation: 509

type in Terminal:

$ mvn --version

then get following result:

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 16:51:28+0300)
Maven home: /opt/local/share/java/maven3
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: ru_RU, platform encoding: MacCyrillic
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"

here in second line we have:

Maven home: /opt/local/share/java/maven3

type this path into field on configuration dialog. That's all to fix!

Upvotes: 37

Nimrod007
Nimrod007

Reputation: 9913

Got to this answer ? probably the answers above are to long ...

just type in :

echo "setenv M2_HOME $M2_HOME" | sudo tee -a /etc/launchd.conf

and restart your mac (thats it!)

restarting is annoying ? just use the command :

grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl

and restart IntelliJ IDEA

Upvotes: 7

craastad
craastad

Reputation: 6472

If you are having this problem with a homebrew installation of maven 3 on the OSX 10.9.4 then check out this blog post.

Upvotes: 3

Ali
Ali

Reputation: 949

In case you don't want to use the M2_HOME and want to direct the IntelliJ to the maven installation you can simply set it by:

  • goto File => Setting => Maven => Maven home directory
  • point to your maven build directory e.g. /usr/local/maven/apache-maven-3.0.4

A better way is to have a symlink e.g. 'latest' for the latest version and point your IntelliJ to use that for consistency, given latest points to the latest version of maven installed on your box.

Upvotes: 3

MikeV
MikeV

Reputation: 1221

Another option is to add the M2_HOME variable at: IntelliJ IDEA=>Preferences=>IDE Settings=>Path Variables

After a restart of IntelliJ, IntelliJ IDEA=>Preferences=>Project Settings=>Maven=>Maven home directory should be set to your M2_HOME variable.

Upvotes: 11

Amir Raminfar
Amir Raminfar

Reputation: 34149

Mac OS apps cannot read bash environment variables. Look at this question Setting environment variables in OS X? to expose M2_HOME to all applications including IntelliJ. You do need to restart after doing this.

Upvotes: 30

Related Questions