首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Maven + Cobertura:错误生成站点和生成参数检查

Maven + Cobertura:错误生成站点和生成参数检查
EN

Stack Overflow用户
提问于 2016-08-24 19:01:22
回答 1查看 1.7K关注 0票数 1

如果不满足Cobertura报告的代码覆盖率限制,我已经将我的项目的Maven构建配置为失败。效果很好。当我使用Maven的站点生成工具时,我已经尝试在Cobertura报告中生成和链接,但是在执行mvn site时我得到了这个错误

代码语言:javascript
运行
复制
Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-site) on project kb-framework: 
failed to get report for org.codehaus.mojo:cobertura-maven-plugin: Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument 
(cobertura-check) on project kb-framework: 
Unable to prepare instrumentation directory. source and destination are the same directory.

使用下面配置的pom.xml,我可以:

  1. 运行mvn verify并查看构建传递/失败
  2. 删除cobertura检查执行和mvn site工作。在构建过程中不进行检查。
  3. 将执行添加到具有cobertura目标的构建段,在验证阶段生成HTML报告,并仍然使用检查目标。

当我按配置执行mvn site时,测试和检测似乎会运行两次。

这一错误似乎也是由于正在进行第二次检测而产生的。如果我将cobertura检查目标替换为cobertura报表生成目标,生成仍然会失败。所以检查的目标不是问题,而是仪器。

所以:有人能帮我配置我的pom.xml以传递/失败mvn verify上的构建,并在执行mvn site时生成并链接到HTML中吗?

以下是pom.xml的相关部分:

代码语言:javascript
运行
复制
<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <check>
          <branchRate>85</branchRate>
          <lineRate>90</lineRate>
          <haltOnFailure>true</haltOnFailure>
          <totalBranchRate>90</totalBranchRate>
          <totalLineRate>90</totalLineRate>
          <packageBranchRate>90</packageBranchRate>
          <packageLineRate>90</packageLineRate>
        </check>
      <instrumentation>
        <excludes>
          <!-- some excludes in here -->
        </excludes>
      </instrumentation>
    </configuration>
    <executions>
      <execution>
        <id>cobertura-clean</id>
        <phase>verify</phase>
        <goals>
          <goal>clean</goal>
        </goals>
      </execution>
      <execution>
        <id>cobertura-check</id>
        <phase>verify</phase>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
  </plugin> 
</plugins>

<reporting>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
     <formats>
       <format>html</format>
       <format>xml</format>
     </formats>
    </configuration>
  </plugin> 
</reporting>
EN

回答 1

Stack Overflow用户

发布于 2016-08-25 12:39:50

我想通了。显然,我需要在站点生成期间使用干净的目标,然后我可以在构建阶段使用我想要的任何目标。我将一个reportSet块添加到pom.xml中,如下所示;现在,我可以在mvn verify期间获得pass/fail,并在mvn site期间链接到报表中,而不会出现错误消息。

pom.xml (问题中描述的生成阶段左):

代码语言:javascript
运行
复制
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
     <formats>
       <format>html</format>
       <format>xml</format>
     </formats>
    </configuration>
    <reportSets>
      <reportSet>
        <id>cobertura-report</id>
        <reports>
          <report>clean</report>
          <report>cobertura</report>
        </reports>
      </reportSet>
    </reportSets> 
  </plugin> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39131147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档