如果不满足Cobertura报告的代码覆盖率限制,我已经将我的项目的Maven构建配置为失败。效果很好。当我使用Maven的站点生成工具时,我已经尝试在Cobertura报告中生成和链接,但是在执行mvn site
时我得到了这个错误
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,我可以:
mvn verify
并查看构建传递/失败mvn site
工作。在构建过程中不进行检查。当我按配置执行mvn site
时,测试和检测似乎会运行两次。
这一错误似乎也是由于正在进行第二次检测而产生的。如果我将cobertura检查目标替换为cobertura报表生成目标,生成仍然会失败。所以检查的目标不是问题,而是仪器。
所以:有人能帮我配置我的pom.xml以传递/失败mvn verify
上的构建,并在执行mvn site
时生成并链接到HTML中吗?
以下是pom.xml的相关部分:
<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>
发布于 2016-08-25 12:39:50
我想通了。显然,我需要在站点生成期间使用干净的目标,然后我可以在构建阶段使用我想要的任何目标。我将一个reportSet块添加到pom.xml中,如下所示;现在,我可以在mvn verify
期间获得pass/fail,并在mvn site
期间链接到报表中,而不会出现错误消息。
pom.xml (问题中描述的生成阶段左):
<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>
https://stackoverflow.com/questions/39131147
复制相似问题