2

我有一个项目,其集成测试由 maven-failsafe-plugin 运行,单元测试由 maven-surefire-plugin 运行。

我使用 jacoco 生成覆盖率报告:

<properties>
    <coverage.reports.dir>${project.build.directory}/coverage-reports</coverage.reports.dir>
    <sonar.jacoco.reportPath>${coverage.reports.dir}/jacoco-unit.exec</sonar.jacoco.reportPath>
    <sonar.jacoco.itReportPath>${coverage.reports.dir}/jacoco-it.exec</sonar.jacoco.itReportPath>
</properties>

[...]

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.5.7.201204190339</version>
            <executions>
                <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <propertyName>jacoco.agent.argLine</propertyName>
                <destFile>${sonar.jacoco.itReportPath}</destFile>
                <dataFile>${sonar.jacoco.itReportPath}</dataFile>
            </configuration>
        </plugin>

[...]

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-failsafe-plugin</artifactId>
          <version>2.5</version>
          <configuration>
              <argLine>${jacoco.agent.argLine}</argLine> 
          </configuration>
    </plugin>

[...]

<profile>
  <id>dev</id>
  <properties>
    <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
  </properties>
</profile>

[...]

当我运行 mvn install 时,成功生成了 Jacoco 覆盖率报告。

但是当我运行 mvn -mvn -Pdev sonar:sonar 时,Sonar 使用 Cobertura 插件而不是 Jacoco。

我努力了:

1)在Sonar设置中将jacoco设置为默认覆盖插件[无效]

2) 在命令行中提供 Jacoco 参数(例如,-Dsonar.core.codeCoveragePlugin=jacoco)[效果不佳]

有人有什么主意吗?谢谢。

顺便说一句,我正在使用声纳 2.8

4

0 回答 0