Skip to content

Installing Sonarqube

Bill Majurski edited this page May 30, 2017 · 5 revisions

Quick local installation

First thing, Sonarqube requires a database to work. It is mostly used to stored to UI configuration for sonarqube web interface. Here we are using MySQL, so you need to install a MySQL Server on your local machine. You can among other other options install MySQL Workbench that provides MySQL Server and a visual tool for database management.

Install mysql on MacOSX

# First get the newest version of brew from GitHub 
brew update

# Then install mysql 
brew install mysql
# Secure your installation of mysql (optional, but usually recommended) 
mysql_secure_installation

If your mysql server is not running, you can use one of these solutions:

# To have launchd start mysql now and restart at login:
brew services start mysql
# Or, if you don't want/need a background service you can just run:
mysql.server start

Note: install MySQL Server on port 3306 so that you won't have to change the rest of the pre-configured environment provided here.

Once MySQL Server is installed you need to create a database for sonar.

Create and configure database for sonar

# Connect your mysql server (if you did not set a password during mysql_secure_installation)
mysql -h localhost -u root
# Connect your mysql server (if you set a password during mysql_secure_installation)
mysql -h localhost -u root -p
# Enter your password...

# Create the database named 'sonar'
CREATE DATABASE sonar;

# CREATE mysql user for sonar
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar';
# To create this user with this password, you might need to update mysql validate_password_policy (only if 'sonar' is refused as a password)
SET GLOBAL validate_password_policy=LOW;
SET GLOBAL validate_password_length=5;

# Give sonar user permissions on sonar database
GRANT ALL PRIVILEGES ON sonar_source.* TO 'sonar'@'localhost';
FLUSH PRIVILEGES;

Install sonar on MacOSX

brew install sonar
brew install sonar-runner (optional)

Configure sonar

Edit file sonar configuration file in $/usr/local/Cellar/sonarqube/6.0/libexec/conf/sonar.properties to uncomment and change the following values.

#--------------------------------------------------------------------------------------------------
# DATABASE Access
# User credentials.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- MySQL 5.6 or greater connector
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Configure sonar in maven

Then, edit the maven settings.xml file and add the following profile:

#!xml

<profile>
	<id>sonar</id>
	<activation>
		<activeByDefault>true</activeByDefault>
	</activation>
	<properties>
		<sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
		<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
		<sonar.jdbc.username>sonar</sonar.jdbc.username>
		<sonar.jdbc.password>sonar</sonar.jdbc.password>
		<!-- La ligne ci-dessous n'est utile que si le port par défaut (9000) est modifié dans le fichier de configuration. -->
		<!--<sonar.host.url>http://url-serveur:1234</sonar.host.url>-->
	</properties>
</profile>

Running Sonnar

To have launchd start sonarqube now and restart at login: brew services start sonarqube Or, if you don't want/need a background service you can just run: sonar console

To access Sonarqube webpage, just open your web browser and load http://localhost:9000/

Finally, to execute a static analyses of your code run this command:

mvn [clean] [install] [...] sonar:sonar

##Install extra plugins##

To install a plugin you can either use the update center or download the jar of the plugin in $SONAR_HOME/extensions/plugins.

How to install extra SonarQube plugins: http://docs.sonarqube.org/display/SONAR/Update+Center

Example of plugin installation (groovy): http://docs.sonarqube.org/display/SONAR/Groovy+Plugin

Resources

Sonarqube documentation: http://docs.sonarqube.org/display/SONAR/Installing+the+Server

Existing tutorial on chapter31: http://chapter31.com/2013/05/02/installing-sonar-source-on-mac-osx/

Clone this wiki locally