在 Sonar 上发布 JUnit 测试报告

Publishing JUnit test reports on Sonar

我有 Maven Java 项目的 JUnit XML 报告,而不是源文件。 我希望 Sonarqube 4.5.7 通过执行以下命令来发布这些报告:"mvn sonar:sonar".

远程服务器安装了Sonarqube,安装了java-plugin-3.8等插件

我所有的 JUnit XML 报告都在一个名为 "reports".

的目录中

我项目根目录下的 pom.xml 如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>***</groupId>
  <artifactId>***</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <name>MEDIATION-DEV1_SMED-Apporteur</name>
  <properties>
    <sonar.junit.reportsPath>reports</sonar.junit.reportsPath>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jdbc.username>***</sonar.jdbc.username>
    <sonar.jdbc.password>***</sonar.jdbc.password>
    <sonar.jdbc.url>jdbc:mysql://***useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
    <sonar.language>java</sonar.language>
    <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
    <sonar.jdbc.dialect>mysql</sonar.jdbc.dialect>
    <sonar.host.url>***</sonar.host.url>   
  </properties>
</project>

当我执行 "mvn sonar:sonar" 时,我得到:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ***
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Apporteur ---
[INFO] Deleting E:\jenkins-slave\workspace\workspace\Mediation-Sonar-Test-Alex\target
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ***
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.0.2:sonar (default-cli) @ Apporteur ---
[INFO] User cache: C:\Users\S046499\.sonar\cache
[INFO] SonarQube version: 4.5.7
[INFO] Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
[INFO] [14:01:41.624] Load global referentials...
[INFO] [14:01:41.861] Load global referentials done: 241 ms
[INFO] [14:01:41.888] User cache: C:\Users\S046499\.sonar\cache
[INFO] [14:01:41.904] Install plugins
[INFO] [14:01:42.141] Install JDBC driver
[INFO] [14:01:42.161] Create JDBC datasource for jdbc:*** useUnicode=true&characterEncoding=utf8
[INFO] [14:01:43.969] Initializing Hibernate
[INFO] [14:01:47.254] views plugin licensed to ***, EVALUATION [Expiration: 2016-06-17, Server: *]
[INFO] [14:01:47.560] Load project referentials...
[INFO] [14:01:48.253] Load project referentials done: 693 ms
[INFO] [14:01:48.255] Load project settings
[INFO] [14:01:48.837] Loading technical debt model...
[INFO] [14:01:48.889] Loading technical debt model done: 52 ms
[INFO] [14:01:48.895] Apply project exclusions
[WARN] [14:01:49.305] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[INFO] [14:01:49.408] -------------  Scan ***
[INFO] [14:01:49.421] Load module settings
[INFO] [14:01:51.137] Language is forced to java
[INFO] [14:01:51.144] Loading rules...
[INFO] [14:01:52.704] Loading rules done: 1560 ms
[INFO] [14:01:52.749] Configure Maven plugins
[INFO] [14:01:53.031] Compare to previous analysis (2016-06-09)
[INFO] [14:01:53.053] Compare over 30 days (2016-05-10, analysis of 2016-06-01 14:22:45.0)
[INFO] [14:01:53.057] No quality gate is configured.
[INFO] [14:01:54.287] Base dir: E:\jenkins-slave\workspace\workspace\Mediation-Sonar-Test-Alex
[INFO] [14:01:54.288] Working dir: E:\jenkins-slave\workspace\workspace\Mediation-Sonar-Test-Alex\target\sonar
[INFO] [14:01:54.292] Source paths: pom.xml
[INFO] [14:01:54.308] Source encoding: windows-1252, default locale: en_US
[INFO] [14:01:54.309] Index files
[INFO] [14:01:54.366] 0 files indexed
[INFO] [14:01:54.368] Quality profile for java: Sonar way
[INFO] [14:01:54.416] Sensor QProfileSensor...
[INFO] [14:01:54.446] Sensor QProfileSensor done: 30 ms
[INFO] [14:01:54.447] Sensor InitialOpenIssuesSensor...
[INFO] [14:01:54.623] Sensor InitialOpenIssuesSensor done: 176 ms
[INFO] [14:01:54.624] Sensor ProjectLinksSensor...
[INFO] [14:01:54.677] Sensor ProjectLinksSensor done: 53 ms
[INFO] [14:01:54.682] Sensor VersionEventsSensor...
[INFO] [14:01:54.733] Sensor VersionEventsSensor done: 51 ms
[INFO] [14:01:54.734] Sensor FileHashSensor...
[INFO] [14:01:54.735] Sensor FileHashSensor done: 1 ms
[INFO] [14:01:54.735] Sensor Maven dependencies...
[INFO] [14:01:55.009] Sensor Maven dependencies done: 273 ms
[INFO] [14:01:55.013] Sensor CPD Sensor (wrapped)...
[INFO] [14:01:55.017] JavaCpdEngine is used for java
[INFO] [14:01:55.018] Sensor CPD Sensor (wrapped) done: 6 ms
[INFO] [14:01:55.464] Execute decorators...
[INFO] [14:01:55.955] Store results in database
[INFO] [14:01:56.238] ANALYSIS SUCCESSFUL, you can browse ***
[INFO] [14:01:56.329] Executing post-job class org.sonar.plugins.dbcleaner.ProjectPurgePostJob
[INFO] [14:01:56.348] -> Keep one snapshot per day between 2016-05-12 and 2016-06-08
[INFO] [14:01:56.354] -> Keep one snapshot per week between 2015-06-11 and 2016-05-12
[INFO] [14:01:56.358] -> Keep one snapshot per month between 2011-06-16 and 2015-06-11
[INFO] [14:01:56.365] -> Delete data prior to: 2011-06-16
[INFO] [14:01:56.375] -> Clean MEDIATION-DEV1_SMED-Apporteur [id=4094]
[INFO] [14:01:56.387] <- Delete aborted builds
[INFO] [14:01:56.491] <- Clean snapshot 7289
[INFO] [14:01:56.646] Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
[INFO] [14:01:56.647] Executing post-job class org.sonar.plugins.core.batch.IndexProjectPostJob
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.157 s
[INFO] Finished at: 2016-06-09T14:01:56+02:00
[INFO] Final Memory: 23M/428M
[INFO] ------------------------------------------------------------------------

当我浏览给定的地址时,(已配置的)仪表板中没有显示任何结果。

你有什么想法吗?

此致。

托马斯

SonarQube 是一个源代码分析器。根据定义,它所做的一切(创建指标、问题……)都必须附加到源文件。因此,如果您没有项目的源代码(在日志中可见:0 files indexed),那么您在项目仪表板中看不到任何内容是正常的。