[macos] 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

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?

This question is related to macos maven intellij-idea osx-lion

The answer is

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.

Similar questions with macos tag:

Similar questions with maven tag:

Similar questions with intellij-idea tag:

Similar questions with osx-lion tag: