Before you Begin
Make sure you have Homebrew installed and are on the latest version of Java. If you don’t update Java then you may run into issues when starting the Sonar server.
To install Homebrew follow the instructions at brew.sh.
To update Java follow the Stack Overflow instructions for How to Install Java 8 on Mac. (It’s pretty much
brew cask install java.)
If you can’t change versions of Java then try out the rest of the steps and see if sonar will run for you. If not, you may need to maintain multiple versions of Java.
If you run into problems using homebrew, then use the
brew doctor command to find out what’s wrong with your system. Follow the instructions it prints out to fix it.
Note: You may compare the steps listed in this guide with this blog article on installing Sonar on Mac. I found some of the steps unnecessary and don’t list them here. See also related guides: Get Started in Two Minutes, Installing a Plugin, JS Sonar Example, and Sonar Project Properties File Example.
brew install sonarin a terminal window
- Find your sonar plugins directory. In my case it was
/usr/local/Cellar/sonar/5.1.2/libexec/extensions/plugins/. Yours will be somewhere ending with “
/libexec/extensions/plugins” and you can normally figure it out by inspecting the output of
brew list sonar.
Install sonar-runner and Modify Your Environment
Use homebrew again. This time install the
sonar-runner formula. Finally, add a little to your
brew install sonar-runner
- Follow the instructions at the end of the install. (If you missed them you can always show them again with
brew info sonar-runner.) NOTE: I found that I didn’t have to modify
sonar-runner.properties. You do have to add something like
Configure and Analyze Your Project
You need to add a properties file to you project, launch the Sonar server, run the analysis, and view the results.
1. In a terminal window launch the Sonar server with
sonar console. Leave it running. (You can kill it when you’re all done with “⌘-.”.)
sonar-project.properties file like this one:
# Required metadata sonar.projectKey=org.familysearch:fs-reservations sonar.projectName=FamilySearch Reservations App sonar.projectVersion=1.680 # Comma-separated paths to directories with sources (required) sonar.sources=assets # Language sonar.language=js
3. In the terminal run the analysis with
4. View the results by navigating to http://localhost:9000. Your project should be listed at the top of the right-hand column.