Harvey
Harvey

Reputation: 171

Sonar MySQL setup

I just downloaded Sonar 3.2 and have configured the sonar.properties files to connect to my local MySql database. I have the following setting enabled:

sonar.jdbc.url:   jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
sonar.jdbc.driverClassName:   com.mysql.jdbc.Driver

I am able to start the server without any errors and am able to log into the Sonar interface however when I run 'mvn sonar:sonar' on my maven project I get the following error:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project vrservices: Can not execute Sonar: Fail to connect to database: Cannot load JDBC driver class 'org.h2.Driver' -> [Help 1]

I have read a few forums that saying to put the following code in the settings.xml file however this still didn't fix the issue.

  <profile>
      <id>sonar</id>
      <activation>
          <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
          <!-- EXAMPLE FOR MYSQL -->
          <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>root</sonar.jdbc.username>
          <sonar.jdbc.password></sonar.jdbc.password>
      </properties>
  </profile>

I was wondering if anyone has come across this issue as well and if so how did you fix it?

Thanks in advance!

Upvotes: 8

Views: 21991

Answers (4)

ZZ 5
ZZ 5

Reputation: 1964

Based on @Mark O'Connor answer: check if the file settings.xml is in right path (/home/YOURUSER/.m2/ or MAVEN_HOME environment variable) and that you run it from correct user - when I ran Sonar Maven Runner as root it couldn't the settings.xml file, because I had it in home folder of my user.

Upvotes: 0

aditya
aditya

Reputation: 61

see that the attribute 'sonar.jdbc.url' in settings.xml and sonar.properties file are the same. secondly create a schema by name 'sonar' before you try to run the sonar server. good luck

Upvotes: 6

SevenEleven
SevenEleven

Reputation: 2474

Maybe you accidentally pasted the "profile" part to the wrong place in your settings.xml? Be sure to have it between the <profiles></profiles> tags. (A colleague of mine just stumbled about a similar issue)

Upvotes: 1

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 78011

If you don't configure the Maven Sonar plugin, it will attempt to connect to the default location for the embedded database that ships with Sonar. Starting with version 3.2 the default embedded database is H2 (replacing derby).

The forum recommendations are correct, I suspect that your Maven instance is not loading the correct settings file. Try running Maven as follows:

mvn -s /path/to/settings/file/setting.xml sonar:sonar

Upvotes: 7

Related Questions