简体   繁体   English

将SonarQube与Maven集成在一起,重复使用Findbugs,PMD,Checkstyle,Surefire和Jacoco报告

[英]Integrating SonarQube with Maven reusing Findbugs, PMD, Checkstyle, Surefire and Jacoco reports

I have a multi-module Java Maven project that already uses Findbugs, Checkstyle, PMD and Jacoco to check the code. 我有一个多模块Java Maven项目,该项目已经使用Findbugs,Checkstyle,PMD和Jacoco来检查代码。 Tests are also run during these analyses. 在这些分析过程中也会进行测试。 I would now like to set up SonarQube to gather the reports generated from the Maven run and display them in SonarQube's dashboard. 我现在想设置SonarQube来收集从Maven运行生成的报告,并将其显示在SonarQube的仪表板上。 So far I have these properties in my parent pom.xml that I found in various postings around the internet: 到目前为止,我在Internet上的各种帖子中找到的父pom.xml中具有以下属性:

<properties>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.surefire.reportsPath>${project.parent.build.directory}/surefire-reports</sonar.surefire.reportsPath>
    <sonar.jacoco.reportPath>${project.parent.build.directory}/coverage-reports/${project.artifactId}-jacoco.exec</sonar.jacoco.reportPath>
    <sonar.findbugs.reportPath>${project.parent.build.directory}/findbugs/findbugs.xml</sonar.findbugs.reportPath>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
</properties>

I didn't change the Checkstyle, Findbugs, Jacoco or PMD plugin configurations. 我没有更改Checkstyle,Findbugs,Jacoco或PMD插件配置。 I added some lines to the Surefire plugin configuration: 我在Surefire插件配置中添加了几行:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <skip>${skip.test}</skip>
                    <testFailureIgnore>${testFailureIgnore}</testFailureIgnore>
                    <argLine>${surefireArgLine}</argLine>
                    <failIfNoTests>${failIfNoTests}</failIfNoTests>
                    <test>AllTests</test>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>org.sonar.java.jacoco.JUnitListener</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>

And these are the Sonar plugins: 这些是Sonar插件:

            <plugin>
                <groupId>org.codehaus.sonar-plugins.java</groupId>
                <artifactId>sonar-jacoco-listeners</artifactId>
                <version>${sonar-jacoco-listeners.version}</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar-maven-plugin.version}</version>
            </plugin>

When running this, I get the message "'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used." 运行此命令时,我收到消息“自4.3版起已弃用'sonar.dynamicAnalysis',因此不应再使用。” But I'm not sure what else to use. 但是我不确定还有什么用。 The relevant JIRA issue doesn't say so either ( https://jira.codehaus.org/browse/SONAR-5185 ) And besides, it doesn't look as if Sonar is picking up anything much from my Maven run. 有关JIRA的问题也没有这样说( https://jira.codehaus.org/browse/SONAR-5185 ),此外,Sonar似乎并没有从我的Maven运行中获得任何好处。 The dashboard only shows values for "Lines of Code", "Duplications", "Complexity", "Directory Tangle Index" and "Unit Test Success". 仪表板仅显示“代码行”,“重复项”,“复杂性”,“目录缠结索引”和“单元测试成功”的值。 Judging from the last entry at least the results from the unit tests are picked up. 从最后一个条目判断,至少要提取单元测试的结果。

I am using Maven 3.2.2, sonar-jacoco-listeners 2.9.1, sonar-maven-plugin 2.5 and SonarQube 4.5.1. 我正在使用Maven 3.2.2,sonar-jacoco-listeners 2.9.1,sonar-maven-plugin 2.5和SonarQube 4.5.1。 The tests are run from within a Jenkins job using "mvn -e test". 这些测试是在Jenkins作业中使用“ mvn -e测试”运行的。

Any pointers or help would be greatly appreciated. 任何指针或帮助将不胜感激。 Maybe what I'm trying to achieve simply isn't possible and/or feasible. 也许我试图实现的目标是不可能和/或可行的。

(In answer to user944849's comment) This is the sonar output for one module build. (回答user944849的评论)这是一个模块构建的声纳输出。

[INFO] [13:39:34.821] -------------  Scan Administration
[INFO] [13:39:34.822] Load module settings
[INFO] [13:39:34.869] Configure Maven plugins
[INFO] [13:39:34.871] Compare to previous analysis (2015-02-25)
[INFO] [13:39:34.872] Compare over 30 days (2015-01-26, analysis of 2015-01-26 05:14:41.328)
[INFO] [13:39:34.873] Compare to previous version (2015-01-16)
[INFO] [13:39:34.874] No quality gate is configured.
[INFO] [13:39:34.889] Initializer FindbugsMavenInitializer...
[INFO] [13:39:34.889] Initializer FindbugsMavenInitializer done: 0 ms
[INFO] [13:39:34.889] Base dir: /mnt/jenkins/jobs/nightlybuild_UVDS_BTH/workspace/trunk/admin
[INFO] [13:39:34.889] Working dir: /mnt/jenkins/jobs/nightlybuild_UVDS_BTH/workspace/trunk/admin/target/sonar
[INFO] [13:39:34.889] Source paths: pom.xml, src/main/java
[INFO] [13:39:34.890] Test paths: src/test/java
[INFO] [13:39:34.890] Binary dirs: target/classes
[INFO] [13:39:34.890] Source encoding: UTF-8, default locale: de_DE
[INFO] [13:39:34.890] Index files
[INFO] [13:39:35.112] 544 files indexed
[INFO] [13:39:42.216] Quality profile for java: DEFAULT
[INFO] [13:39:42.276] Sensor JavaSquidSensor...
[INFO] [13:39:42.303] Java Main Files AST scan...
[INFO] [13:39:42.303] 407 source files to be analyzed
[INFO] [13:39:52.304] 245/407 files analyzed
[INFO] [13:39:58.548] 407/407 source files analyzed
[INFO] [13:39:58.549] Java Main Files AST scan done: 16246 ms
[INFO] [13:39:58.566] Java bytecode scan...
[INFO] [13:39:58.895] Java bytecode scan done: 329 ms
[INFO] [13:39:58.896] Java Test Files AST scan...
[INFO] [13:39:58.896] 137 source files to be analyzed
[INFO] [13:39:59.676] Java Test Files AST scan done: 780 ms
[INFO] [13:39:59.676] 137/137 source files analyzed
[INFO] [13:39:59.677] Package design analysis...
[INFO] [13:40:00.767] Package design analysis done: 1090 ms
[INFO] [13:40:00.788] Sensor JavaSquidSensor done: 18512 ms
[INFO] [13:40:00.796] Sensor QProfileSensor...
[INFO] [13:40:00.797] Sensor QProfileSensor done: 1 ms
[INFO] [13:40:00.797] Sensor InitialOpenIssuesSensor...
[INFO] [13:40:00.839] Sensor InitialOpenIssuesSensor done: 42 ms
[INFO] [13:40:00.839] Sensor ProjectLinksSensor...
[INFO] [13:40:00.843] Sensor ProjectLinksSensor done: 4 ms
[INFO] [13:40:00.843] Sensor VersionEventsSensor...
[INFO] [13:40:00.850] Sensor VersionEventsSensor done: 7 ms
[INFO] [13:40:00.850] Sensor FileHashSensor...
[INFO] [13:40:00.863] Sensor FileHashSensor done: 13 ms
[INFO] [13:40:00.863] Sensor SurefireSensor...
[INFO] [13:40:00.863] parsing /mnt/jenkins/jobs/nightlybuild_UVDS_BTH/workspace/trunk/uvds-admin/target/surefire-reports
[INFO] [13:40:00.920] Sensor SurefireSensor done: 57 ms
[INFO] [13:40:00.921] Sensor Maven dependencies...
[INFO] [13:40:01.086] Sensor Maven dependencies done: 165 ms
[INFO] [13:40:01.090] Sensor CPD Sensor (wrapped)...
[INFO] [13:40:01.090] JavaCpdEngine is used for java
[INFO] [13:40:01.101] Cross-project analysis disabled
[INFO] [13:40:02.295] Sensor CPD Sensor (wrapped) done: 1205 ms
[INFO] [13:40:02.432] Execute decorators...

Here is a POM with a configuration for SonarQube 4.5.1 that works for me, at least for Surefire and JaCoCo (see the results ). 这是一个为SonarQube 4.5.1进行配置的POM ,它至少对Surefire和JaCoCo有用(请参阅结果 )。

The project is run with mvn clean install -Dsonar . 该项目使用mvn clean install -Dsonar运行。

I don't use FindBugs in my project.. 我不在项目中使用FindBugs。

Thank you for your answers. 谢谢您的回答。 Sonar now picks up the code coverage. 现在,Sonar加快了代码覆盖范围。 The problem was the path I provided for the Jacoco exec files. 问题是我为Jacoco exec文件提供的路径。 I used the variable parent.project.build.directory. 我使用了变量parent.project.build.directory。 This didn't work. 这没用。 I'm now storing the exec files in the projects' build directory. 我现在将exec文件存储在项目的build目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM