1

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.

Sylvester Loreto
  • 404
  • 6
  • 18

2 Answers2

1

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.

Community
  • 1
  • 1
  • Thank you for your comment. I'm aware that which ever database is used it's sensitive details will be exposed in the profile. However, I'm looking for a solution where I could have a job in a CI such Jenkins or Bamboo where only the Sonar Host Url would be enough. I don't want to expose DB details in pom.xml where everybody have access to it. The DB details would be stored in the Sonarqube Machine in the conf/sonar.properties file where only the Sys Admin have access to it. If anyone knows how this could be done, please let me know. Cheers :-) – Sylvester Loreto Sep 16 '15 at 19:34
  • I'm also interested in the same thing as SylvesterAbrue.. I hope someone has a solution for this. – Fadi Nov 10 '15 at 21:02
  • Apparently they changed this after 5.2, you no longer need the JDBC connection properties in the maven settings: http://stackoverflow.com/a/7520119/400503 – fletchowns Nov 17 '16 at 01:57
0

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.

johnnymnmonic
  • 774
  • 8
  • 11