Focus on IT Recommend

Home > android - Sonar fails to connect to mysql, running from gradle

android - Sonar fails to connect to mysql, running from gradle

I have a sonar configuration that looks like this:

sonar.jdbc.validationQuery=select 1

And when running this from my gradle script, which looks like this:

  sonarProperties {

        property "sonar.projectKey", "sonar-example"
        property "sonar.projectName", "sonar example"
        property "sonar.projectVersion", "1.0"

        property "sonar.sources", "src/main/java"
        property "sonar.binaries", "build"
        property "sonar.test", "src/test/java"

        property "sonar.language", "java"
        property "sonar.profile", "Android Lint"
        property "", "lint-report.xml"
        property "sonar.dynamicAnalysis", "reuseReports"
        property "sonar.sourceEncoding", "UTF-8"

        property "sonar.junit.reportsPath", "build/outputs/reports/coverage/debug"
        property "sonar.cobertura.reportPath", "build/outputs/reports/coverage/debug/cobertura.xml"
        property "", "cobertura"

        property "", "http://localhost:9000/sonar"
        property "sonar.jdbc.username", "sonar"
        property "sonar.jdbc.password", "sonar"


I get the following error:

pepes-MacBook-Pro-4:android-robolectric-test pepe$ ./gradlew sonarRunner
SonarQube Runner 2.3
Java 1.7.0_75 Oracle Corporation (64-bit)
Mac OS X 10.10.3 x86_64
INFO: Runner configuration file: NONE
INFO: Project configuration file: /Users/pepe/development/android-robolectric-test/app/build/tmp/sonarRunner/
INFO: Default locale: "sv_SE", source code encoding: "UTF-8"
INFO: Work directory: /Users/pepe/development/android-robolectric-test/app/build/sonar
INFO: SonarQube Server 5.0.1
10:24:55.133 INFO  - Load global referentials...
10:24:55.406 INFO  - Load global referentials done: 276 ms
10:24:55.410 INFO  - User cache: /Users/pepe/.sonar/cache
10:24:55.418 INFO  - Install plugins
10:24:55.428 INFO  - Download sonar-findbugs-plugin-2.4.jar
10:24:55.545 INFO  - Download sonar-cpd-plugin-5.0.1.jar
10:24:55.552 INFO  - Download sonar-scm-git-plugin-5.0.1.jar
10:24:55.608 INFO  - Download sonar-core-plugin-5.0.1.jar
10:24:55.615 INFO  - Download sonar-java-plugin-2.8.jar
10:24:55.675 INFO  - Download sonar-scm-svn-plugin-5.0.1.jar
10:24:55.679 INFO  - Download sonar-l10n-en-plugin-5.0.1.jar
10:24:55.683 INFO  - Download sonar-email-notifications-plugin-5.0.1.jar
10:24:55.736 INFO  - Install JDBC driver
10:24:55.740 INFO  - Download mysql-connector-java-5.1.27.jar
10:24:55.753 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
INFO: ------------------------------------------------------------------------
INFO: ------------------------------------------------------------------------
Total time: 3.580s
Final Memory: 7M/245M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: Fail to connect to database
ERROR: Caused by: Cannot create PoolableConnectionFactory (Connection is broken: " Connection refused: localhost" [90067-176])
ERROR: Caused by: Connection is broken: " Connection refused: localhost" [90067-176]
ERROR: Caused by: Connection refused
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
:app:sonarRunner FAILED

FAILURE: Build failed with an exception.

Why is it connecting to H2 and not mysql? I've read the post with the same problem here and here, but the solution seems to have been something related to Maven. I don't use Maven, I use Gradle instead.


property "sonar.jdbc.url", "jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"

should be added to sonarproperties above.

android gradle sonarqube sonar-runner
edited Apr 30 '15 at 10:33 asked Apr 30 '15 at 9:09 peuhse 312 5 21


2 Answers


The (most important) property sonar.jdbc.url is missing in the sonarProperties section of your Gradle script, so no wonder why it is trying to connect to H2 (which is the default value for this property).

answered Apr 30 '15 at 10:17 Fabrice - SonarSource Team 17.5k 2 33 41      Of course! Good catch! –  peuhse Apr 30 '15 at 10:30      @peuhse Please accept the answer if it solved your problem! –  Fabrice - SonarSource Team Apr 30 '15 at 11:57


Have you tried replacing property "", "http://localhost:9000/sonar" with property "", "" ?

answered Apr 30 '15 at 9:20 k3v1n4ud3 1,389 7 14      Yes, and it's the same error still. –  peuhse Apr 30 '15 at 9:32



------splitte line----------------------------