Sonar 无法从 gradle 连接到 mysql、运行

Sonar fails to connect to mysql, running from gradle

我的声纳配置如下所示:

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncod$
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.validationQuery=select 1

sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000

当 运行 来自我的 gradle 脚本时,它看起来像这样:

  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 "sonar.android.lint.report", "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 "sonar.java.coveragePlugin", "cobertura"

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

    }

我收到以下错误:

pepes-MacBook-Pro-4:android-robolectric-test pepe$ ./gradlew sonarRunner
:app: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/sonar-project.properties
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: EXECUTION FAILURE
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: "java.net.ConnectException: Connection refused: localhost" [90067-176])
ERROR: Caused by: Connection is broken: "java.net.ConnectException: Connection refused: localhost" [90067-176]
ERROR: Caused by: Connection refused
ERROR:
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.

为什么它连接到 H2 而不是 mysql?我读过 post 有同样的问题 here and here,但解决方案似乎与 Maven 相关。我不使用 Maven,而是使用 Gradle。

编辑:

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

应该添加到上面的 sonarproperties 中。

您是否尝试过将 property "sonar.host.url", "http://localhost:9000/sonar" 替换为 property "sonar.host.url", "http://127.0.0.1:9000/sonar"

Gradle 脚本的 sonarProperties 部分缺少(最重要的)属性 sonar.jdbc.url,所以难怪它为什么要尝试连接到 H2 (这是此 属性 的默认值)。