7

My maven build works fine in IntelliJ IDEA. That is not the issue. The issue is relating to SonarQube Community Plugin.

ERROR 17:08:38.358 > java.io.IOException: Cannot run program "mvn" (in directory "/Users/chrismanning/Projects/Registry/registry/idea-files"): error=2, No such file or directory

Local analysis script:

mvn sonar:sonar 
-DskipTests=true 
-Dsonar.analysis.mode=issues
-Dsonar.scm.enabled=false 
-Dsonar.scm-stats.enabled=false 
-Dissueassignplugin.enabled=false 
-Dsonar.preview.excludePlugins=emailnotifications,issueassign 
-Dsonar.report.export.path=sonar-report.json

I definitely have maven installed and in my path. (it's symlinked in /usr/local/bin)

chrismanning@Chriss-MacBook-Pro:~/Projects/Registry/registry/idea-files$ mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T12:29:23-05:00)
Maven home: /Users/chrismanning/apache-maven-3.2.5
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"

M2_HOME and PATH are propely defined in /etc/launchd.conf

Chris Manning
  • 499
  • 5
  • 14
  • 1
    Sorry, but this might be a possible duplicate: http://stackoverflow.com/questions/7053666/maven-home-m2-home-not-being-picked-up-by-intellij-idea – hooknc Mar 21 '16 at 21:43
  • Followed solution for that and moved my M2_HOME declaration and PATH additions to that file. (then restarted IntelliJ) No luck here – Chris Manning Mar 21 '16 at 22:27
  • Also tried restarting PC per that answer's directions just in case. Still no luck – Chris Manning Mar 21 '16 at 22:35
  • 1
    @hooknc That was actually the problem, but that stackoverflow link did not provide the proper solution. That method of setting environmental variables is outdated for Mac OS X Yosemite. – Chris Manning Mar 22 '16 at 17:53

1 Answers1

22

If you're using Yosemite (like I am) you must set environmental variables this way

  1. Create new file at ~/Library/LaunchAgents/environment.plist

  2. Add this code block and modify to appropriately set your environmental variables

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>my.startup</string>
      <key>ProgramArguments</key>
      <array>
        <string>sh</string>
        <string>-c</string>
        <string>
        launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
        launchctl setenv M2_HOME /Users/chrismanning/apache-maven-3.2.5
        </string>        
      </array>
      <key>RunAtLoad</key>
      <true/>
    </dict>
    </plist>
    
  3. Save and restart your computer. This is the proper way to load Yosemite environmental variables

If you are using an older version of Mac OS X, see this answer

Setting environment variables in OS X?

Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
Chris Manning
  • 499
  • 5
  • 14
  • Good job on finding the answer yourself. Don't forget to select your answer as the right answer. – hooknc Mar 23 '16 at 20:40
  • Does this work for terminal as well? Or, do I have to add `export JAVA_HOME="/Library/Java/..."` in some where else too (like, `/etc/profile` or `~/.bash_profile`)? – Ali Ok Jun 22 '16 at 01:18
  • Should work fine in terminal. Just make sure to restart your computer after adding the launch agent file. However if you're running El Capitan I think the way to set the variables changed. I haven't upgraded my Mac yet but a coworker was having problems with this on El Capitan. – Chris Manning Jun 23 '16 at 07:57
  • 1
    Be sure to use the *RAW Paste Data* from that pastebin snippet (the formatted version is borked). – Perry Jun 27 '16 at 18:42
  • Ah, I'll have him try that. Thanks Perry. – Chris Manning Jun 28 '16 at 17:18