java - Sonar jacoco报告未执行

标签 java sonarqube maven-2 jacoco-maven-plugin

我添加了使用 Sonar 生成 jacoco 覆盖率报告的代码。但是当我运行 mvn clean install sonar:sonar 时。仅执行与 Sonar 相关的功能。未生成 Jacoco 覆盖率报告。

<!-- Below plugin ensures the execution of test cases during maven build -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>${runSuite}</include>
                    </includes>
                </configuration>
            </plugin>

            <!-- Sonar-JaCoCo integration plugin -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.6.201602180812</version>
                <configuration>
                    <destFile>${sonar.jacoco.reportPath}</destFile>
                    <append>true</append>
                </configuration>
                <executions>
                    <execution>
                        <id>agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>

            <properties>
        <sonar.sources>src/main</sonar.sources>
        <sonar.tests>src/test</sonar.tests>
        <!-- Below property indicates the pattern of the test suite -->
        <runSuite>**/*Suite.class</runSuite>
        <!-- Sonar-JaCoCo properties -->
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.language>java</sonar.language>
    </properties>

最佳答案

Java 插件不再为您运行单元测试。据记录here ,您需要在分析之前自己启动它们:

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true

关于java - Sonar jacoco报告未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40145715/

相关文章:

java - 如何调试使用 maven 构建的 android 应用程序

maven-2 - Maven:删除的文件(antrun)仍在最终war文件中

java - 尝试反序列化子类时出现"com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id"

java - 将 HttpRequest 对象作为参数传递给其他对象方法是个坏主意吗?

macos - 在 OS X Server 上运行的 Tomcat 6 上启动时 Sonar 抛出异常

build - SonarQube 扫描仪因线路超出范围而失败

java - 使用 eclipse 在已安装的 Glassfish 上调试 Maven Web 应用程序

java - 使用 RollingFileAppender 进行毫秒级滚动时 Log4j2 'Unable to move file' 错误

Java:剧院座位表

api - 用于检索使用特定质量配置文件的所有项目/资源的 SonarQube Web API 是什么?