Laurent Hinoul

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - John F. Woods

How to change Sonar default database

Sonar uses a Derby or H2 as default database. When running Sonar, it says that these databases may only be used for evaluation. Now, in this article, I will tell you how to change the default database and how to configure Maven to use it.

Installation

First, download Sonar from its website at http://www.sonarqube.org/downloads/. Then, extract the zip file and the we can start configuring. Note that I will demonstrate the configuration with a MySQL database. You can use any other database you prefer.

Configuration

In the sonar folder, go to the conf-folder and open sonar.properties. You will see many commented lines. First comment line 48. That’s the connection String to the default database Sonar uses.

Then, I will change line 40 and 41. These are the login credentials to my database. For MySQL, it will be:

After that, we need to uncomment the MySQL connection string. (Note that other database may uncomment more properties).

When that’s finished, we can start Sonar, but before we do that, make sure your database is running and that the Sonar database is created!. To start sonar, go to the bin-folder, select your operating system folder and click on StartSonar.xxx. For me, it will be windows-x86-32 and StartSonar.bat. After starting up, a command box will appear, create the needed tales in your database and start up. To see if Sonar is up and running, got to http://localhost:9000

Eclipse plugin

Now sonar is up and running, we need to configure Eclipse and Maven to use sonar. First, install the Eclipse plugin for Sonar. You can find it at http://dist.sonar-ide.codehaus.org/eclipse/. After installing the plugin, we need a little configuration in Maven to use the plugin.

Maven configuration

When you run Sonar in Maven without a configuration, Maven will still use the default database. We need to add a profile in the Maven settings. In the .m2 folder, open the settings.xml. Then add the code below. You also need to do that in the settings.xml in your Maven conf folder. You can find other database profiles at http://mojo.codehaus.org/sonar-maven-plugin/examples/use-enterprise-database.html

Update Maven in Eclipse

Now sonar and Maven are configured, we need to update your project in Eclipse. Right click on your project in Eclipse, go to Maven en click on Update Project. Then the Maven settings will become active.

updateMavenSonar

updateProjectsMavenSonar

Running Sonar in Eclipse

Now we are ready to run Sonar in Eclipse. Right click on your root project, select run as and click on run configurations. Create a new Maven build and insert into your goal: clean install sonar:sonar. Then click on run and your project will show up in Sonar. Enjoy!

runSonar

8 comments for “How to change Sonar default database

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: