我有一个项目,其集成测试由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使用Cobertura插件而不是Jacoco .

我试过了:

1)将jacoco设置为Sonar设置中的默认coverage插件[不起作用]

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

有谁有想法吗?谢谢 .

顺便说一下,我正在使用Sonar 2.8