【问题标题】:SonarQube try to use 'org.h2.Driver' when MySql has been specified instead当指定 MySql 时,SonarQube 尝试使用 'org.h2.Driver'
【发布时间】:2016-08-24 18:15:14
【问题描述】:

要求mvn clean install sonar:sonar 将快照从机器 Maven 部署/安装到机器 SonarQube,它将把它存储在具有 MySql 数据库的机器 MySql 中。 Machine MySql 仅对 Machine SonarQube 可见。机器 SonarQube 对 Intranet 可见,Intranet 中的每个人都可以访问它。 从 Machine Maven 运行 mvn clean install sonar:sonar 时会出现以下错误:

[ERROR] 未能执行目标 org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project my-project:连接数据库失败:无法加载 JDBC 驱动程序类 'org.h2.Driver' -> [帮助 1]

Machine Maven 在 ~/.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>

根据here 中的文档添加了sonar-maven-plugin。

sonar-maven-plugin 也被添加为 pom.xml 的依赖项:

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

我知道documentation 要求在我不想暴露给其他人的 maven 设置声纳配置文件属性中指定 jdbc 驱动程序、url、用户名和密码,因此这已在 Machine SonarQube conf 中指定/sonar.properties

有没有办法通过 Machine SonarQube 将这些快照解聚/安装到 Machine MySql,从 Machine Maven 运行“mvn clean install sonar:sonar”?

提前致谢。

【问题讨论】:

    标签: java mysql maven jdbc


    【解决方案1】:

    在这篇帖子Sonar fails to connect to mySQL always tries jdbc:h2:tcp://localhost/sonar 中,您的属性似乎不完整。

    尝试将以下属性添加到您的 maven 设置文件 ~/.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>
    

    注意:您的&lt;sonar.jdbc.url&gt;&lt;/sonar.jdbc.url&gt; 取决于您使用的数据库。

    【讨论】:

    • 感谢您的评论。我知道无论使用哪个数据库,它的敏感细节都会在配置文件中公开。但是,我正在寻找一种解决方案,让我可以在 Jenkins 或 Bamboo 这样的 CI 中找到一份工作,其中只有 Sonar Host Url 就足够了。我不想在每个人都可以访问的 pom.xml 中公开数据库详细信息。数据库详细信息将存储在 Sonarqube 机器的 conf/sonar.properties 文件中,只有系统管理员可以访问它。如果有人知道如何做到这一点,请告诉我。干杯:-)
    • 我也对和 SylvesterAbrue 一样的东西感兴趣。我希望有人能解决这个问题。
    • 显然他们在 5.2 之后更改了这一点,您不再需要 maven 设置中的 JDBC 连接属性:stackoverflow.com/a/7520119/400503
    【解决方案2】:

    要在jenkins中使用,必须在jenkins management/sonarQube server/advanced settins中配置sonar plugin settins -> DDBB URL 像这样

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

    适用于 sonarQube 5.1 或更低版本。在 5.2 或更早版本中嵌入了 DDBB,这不是必需的。

    【讨论】:

      猜你喜欢
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 2021-12-15
      • 1970-01-01
      • 2016-12-03
      • 2023-03-23
      • 2021-01-01
      相关资源
      最近更新 更多