SonarQube没有读取多模块项目的父pom目标目录中的集成JaCoCo测试覆盖率

时间:2015-12-18 17:20:10

标签: sonarqube jacoco sonarqube5.2

我已按照说明为我们的声纳项目启用了单元和积分测试: http://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Integration+Tests+for+Java+Project

我的pom设置几乎与此示例中给出的设置相同: https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco

父pom设置:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-agent-for-it</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <excludes>
                                    <exclude>static/**/*.jar</exclude>
                                    <exclude>static/**/*.class</exclude>
                                </excludes>
                            </configuration>
                            </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

我们有一个特定的模块将运行集成测试:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <!-- The destination file for the code coverage report has to be set to the same value
                            in the parent pom and in each module pom. Then JaCoCo will add up information in
                            the same report, so that, it will give the cross-module code coverage. -->
                        <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

我已将Sonar配置为寻找UT和IT: enter image description here

单元测试报告正常,但不是集成测试。在Bamboo日志中,我可以看到声纳正在所有子模块中寻找集成测试和单元测试,但当它到达父模块时,它永远不会运行JaCoCoSensor或JaCoCoItSensor。这两个传感器都针对每个模块项目运行。我还注意到每个模块项目都有一个JaCoCoOverallSensor,但不是父项目。

如何让JaCoCoItSensor为父项目运行?

1 个答案:

答案 0 :(得分:1)

我添加了一些配置属性,它开始工作。

父pom.xml添加:

<properties>
    ...
    <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.language>java</sonar.language>
</properties>

IT测试模块我改变了:

<destFile>${sonar.jacoco.itReportPath}/../target/jacoco-it.exec</destFile>

对此:

<destFile>${sonar.jacoco.itReportPath}</destFile>