I’ll guide you through installing sonar-scanner on Mac. There are two main methods:
- Using Homebrew (Recommended):
# Install Homebrew first if you haven't already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install sonar-scanner
brew install sonarqube-scanner
- Manual Installation:
# Create a directory for sonar-scanner (optional)
mkdir ~/sonar-scanner
# Download the latest version
curl -o ~/sonar-scanner/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-macosx.zip
# Unzip the downloaded file
cd ~/sonar-scanner
unzip sonar-scanner.zip
# Add to PATH in your shell config file (.zshrc or .bash_profile)
echo 'export PATH=$PATH:~/sonar-scanner/sonar-scanner-4.8.0.2856-macosx/bin' >> ~/.zshrc
# Or for bash users:
# echo 'export PATH=$PATH:~/sonar-scanner/sonar-scanner-4.8.0.2856-macosx/bin' >> ~/.bash_profile
# Reload your shell configuration
source ~/.zshrc # or source ~/.bash_profile
To verify the installation:
sonar-scanner -v
Configure sonar-scanner:
- Create a
sonar-project.properties
file in your project root:
sonar.projectKey=your-project-key
sonar.projectName=Your Project Name
sonar.projectVersion=1.0
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.host.url=http://localhost:9000
- Replace the configuration values according to your SonarQube server settings.
Common issues and solutions:
- If you get permission errors, you might need to use
sudo
for some commands - Make sure your SonarQube server is running before scanning
- Check if the paths in your configuration file are correct
- Verify your network connection to the SonarQube server