I had issues in Yosemite with IntelliJ always complaining that it couldn’t see my M2_HOME variable, even though I had it in my .bash_profile. Turns out that only works in the terminal.
In any case, this worked — I verified it on my Mac, which runs v10.10.5.
1. Save this plist in ~/Library/LaunchAgents/ as custom.startup.plist
3. That's it!