findbugs pmd checkstyle cobertura 的 Maven sonar 插件配置

标签 maven sonarqube findbugs checkstyle cobertura

我需要一些帮助来为 Maven 项目设置代码质量插件。
我有一个多模块项目。虽然我在构建过程中配置了 pmdcheckstylefindbugscobertura,但我可以生成 xml 报告对于每个插件,我都面临着在我的项目中配置 Sonar 插件的一些挑战。

我不确定如何解决这个问题:

  1. 我应该在执行 Sonar 时重用这些插件生成的报告吗?如果是这样,我的 Sonar 插件配置应该是什么?
  2. 如果我使用嵌入式 pmdcheckstylefindbugscobertura 插件运行 Sonar ,我该如何配置它们仅针对特定包运行或对 com.mycompany.- 结构进行 findbugs 分析。
  3. 最后,无论是在 Sonar 外部还是在 Sonar 内部运行 cobertura,我都无法在 Sonar 中获取覆盖率报告。

我在下面有我的 pom 供审查。任何帮助将不胜感激。

这是在我的根 pom 中构建部分的插件部分:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <instrumentation>
                    <includes>
                        <include>com/mycompany/**/*.class</include>
                    </includes>                 
                </instrumentation>
                <formats>
                    <format>xml</format>
                </formats>
            </configuration>                
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>2.7.1</version>
            <configuration>
                <sourceEncoding>utf-8</sourceEncoding>
                <minimumTokens>100</minimumTokens>
                <targetJdk>1.6</targetJdk>
                <includes>
                    <include>com/mycompany/**/*.java</include>                      
                </includes>
                <excludeRoots>
                    <excludeRoot>target/generated-sources/*</excludeRoot>
                </excludeRoots>
            </configuration>
        </plugin>   
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <onlyAnalyze>com.mycompany.-</onlyAnalyze>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <includes>com/mycompany/**/*.java</includes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.0</version>
        </plugin>

最佳答案

1) should I reuse the reports generated by these plugins while executing sonar? if so what should my sonar plugin configuration be?

Sonar 不提供重用这些插件生成的报告的机制。您可以通过 quality profiles 配置规则.

2) if I run sonar with embedded pmd, checkstyle, findbugs and cobertura plugins, how do I configure them to run only for specific packages or make findbugs analyze on "com.mycompany.-" structure.

Sonar 网络用户界面允许您为您的 findbugs 过滤器指定排除项。 Cobertura 也是如此。不确定 pmd、checkstyle。

3) lastly i cannot get coverage report in sonar, either running cobertura external to sonar or within sonar.

这可能是由于 jacoco being the default code coverage engine .您可以按照说明运行 mvn clean verify/install sonar:sonar 并查看它是否有效。

关于findbugs pmd checkstyle cobertura 的 Maven sonar 插件配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11910604/

相关文章:

SonarQube 5.1.1,在哪里定义文件排除模式?

sonarqube - 一个项目的多个质量概况

java - 生成用于单元和集成测试的 Sonar 覆盖报告

constructor - Findbugs 在验证构造函数参数时报告已知空值的负载

java - Findbugs 错误 - Bug : br is null guaranteed to be dereferenced on exception path

java - HTTP 状态 500 - java.lang.LinkageError

maven - 如何增加 Ant 永久元的大小?

java - 自动装箱错误

eclipse - 资源不在 Java 项目的构建路径上

java - 使用 Maven、Jersey、Tomcat、@ApplicationPath、无 web.xml 调试 IncompatibleClassChangeError