Cobertura报道和检查

时间:2015-07-15 17:53:07

标签: java maven cobertura

我目前正在开发一个应用程序,我想生成XML覆盖率报告,并在构建时检查是否达到了覆盖范围限制。

我在让他们一起工作时遇到了问题。

<project>
...
<build>
  ...
  <plugins>
    ...
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <check>
        <branchRate>100</branchRate>
        <lineRate>100</lineRate>
        <haltOnFailure>true</haltOnFailure>
        <totalBranchRate>100</totalBranchRate>
        <totalLineRate>100</totalLineRate>
        <packageLineRate>100</packageLineRate>
        <packageBranchRate>100</packageBranchRate>
      </check>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>clean</goal>
          <goal>check</goal>
          <goal>cobertura</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

实际上,我收到以下错误:&#34;无法准备检测目录。源和目的地是相同的目录&#34;。

但如果我只使用一个目标就可以了。随着&#34; cobertura&#34;我得到了我的XML报告,并且&#34;检查&#34;如果应用程序没有达到限制,则应用程序会失败。

我如何一起使用它们? 我使用的是Java 8和Maven 3。

1 个答案:

答案 0 :(得分:0)

添加多个执行,每个执行只有一个目标。并确保它们按顺序运行,将每个分配给一个maven阶段。类似的东西(你可能想改变你使用的阶段):

<project>
...
<build>
  ...
  <plugins>
    ...
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <check>
        <branchRate>100</branchRate>
        <lineRate>100</lineRate>
        <haltOnFailure>true</haltOnFailure>
        <totalBranchRate>100</totalBranchRate>
        <totalLineRate>100</totalLineRate>
        <packageLineRate>100</packageLineRate>
        <packageBranchRate>100</packageBranchRate>
      </check>
    </configuration>
    <executions>
      <execution>
        <id>clean-corbertura</id>
        <goals>
          <goal>clean</goal>
        </goals>
          <phase>initialize</phase>
      </execution>
      <execution>
        <id>check-corbertura</id>
        <goals>
          <goal>check</goal>
        </goals>
        <phase>process-resources</phase>
      </execution>
      <execution>
        <id>run-corbertura</id>
        <goals>
          <goal>cobertura</goal>
        </goals>
        <phase>prepare-package</phase>
      </execution>
    </executions>
  </plugin>
</plugins>

https://maven.apache.org/guides/mini/guide-configuring-plugins.html

的更多信息
相关问题