【问题标题】:Sonar fails to connect to mysql, running from gradle声纳无法连接到 mysql,从 gradle 运行
【发布时间】:2015-07-09 21:51:06
【问题描述】:

我的声纳配置如下所示:

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?我已经阅读了同样问题的帖子herehere,但解决方案似乎与 Maven 相关。我不使用 Maven,而是使用 Gradle。

编辑:

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

应该添加到上面的声纳属性中。

【问题讨论】:

    标签: android gradle sonarqube sonar-runner


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 1970-01-01
        • 2011-11-23
        • 1970-01-01
        • 2015-10-23
        • 2021-02-15
        • 1970-01-01
        相关资源
        最近更新 更多