Sylvester Loreto
Sylvester Loreto

Reputation: 452

SonarQube try to use 'org.h2.Driver' when MySql has been specified instead

Requirement is to mvn clean install sonar:sonar deploy/install snapshots from Machine Maven to Machine SonarQube which will store it in Machine MySql which has a MySql database. Machine MySql is only visible to Machine SonarQube. Machine SonarQube is visible to the intranet which everyone within the intranet can access it. When running mvn clean install sonar:sonar from Machine Maven the following error occurs:

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

Machine Maven has the following profile in ~/.m2/settings.xml:

<profile>
    <id>sonar</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <sonar.host.url>https://sonarqube.myproject.com</sonar.host.url>
    </properties>
</profile>

sonar-maven-plugin has been added as per documentation found in here.

Also sonar-maven-plugin has been added as a dependency to the pom.xml:

<dependency>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>2.5</version>
</dependency>

I know the documentation asks for jdbc driver, url, username and password to be specified in maven settings sonar profile properties which I don't want to expose to other people, so this has been specified in the Machine SonarQube conf/sonar.properties

Is there a way to depoly/install these snapshots to Machine MySql through Machine SonarQube run the 'mvn clean install sonar:sonar' from Machine Maven?

Thanks in advance.

Upvotes: 1

Views: 3149

Answers (2)

johnnymnmonic
johnnymnmonic

Reputation: 804

To use in jenkins, it must configure the sonar plugin settins in the jenkins management/sonarQube server/advanced settins -> the DDBB URL like this

jdbc:mysql://localhost:3306/sonardb?useUnicode=true&characterEncoding=utf8
&rewriteBatchedStatements=true&useConfigs=maxPerformance

user=sonar
pwd =sonnar

for sonarQube version 5.1 or lower. In 5.2 or prior the DDBB is embeded and this is not necesary.

Upvotes: 0

Augusto Jimenez
Augusto Jimenez

Reputation: 71

In this post Sonar fails to connect to mySQL always tries jdbc:h2:tcp://localhost/sonar, it´s appear your properties are incompleted.

Try to add the follow properties to the "sonar profile" in your maven settings file ~/.m2/settings.xml :

<profile>
  <id>sonar</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <properties>
    <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url>
    <sonar.jdbc.username>user_of_the_sonar_database</sonar.jdbc.username>
    <sonar.jdbc.password>password_of_the_userdatabase</sonar.jdbc.password>
    <sonar.host.url>http://localhost:9000</sonar.host.url>
  </properties>
</profile>

Note: Your <sonar.jdbc.url></sonar.jdbc.url> depens on the database you use.

Upvotes: 1

Related Questions