我有一个maven多模块项目,我使用网站上的jacoco示例配置来创建代码覆盖率报告:(http://eclemma.org/jacoco/trunk/doc/examples/build/pom.xml)
所以我的pom看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dti</groupId>
<artifactId>dti-parent</artifactId>
<version>1.0.1</version>
</parent>
<groupId>com.dti.myproject</groupId>
<artifactId>myproject-build-all</artifactId>
<version>6.5.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>myproject</name>
<modules>
<module>../myproject-config</module>
<module>../myproject-messages</module>
<module>../myproject-persistence</module>
<module>../myproject-resources</module>
<module>../myproject-service</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7-SNAPSHOT</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<!-- implementation is needed only for Maven 2 -->
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<!-- implementation is needed only for Maven 2 -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
当我执行mvn:test时,在模块中生成了surefire报告,它们看起来很好。但是,当我运行mvn:verify时,jacoco不会创建报告,并且控制台输出显示:
[INFO] --- jacoco-maven-plugin:0.7.7-SNAPSHOT:report (default-report) @ myproject-build-all ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7-SNAPSHOT:check (default-check) @ myproject-build-all ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\workspaces\release-trunk\myproject-build-all\target\jacoco.exec
有人知道如何修复此错误吗?
答案 0 :(得分:2)
<phase>prepare-package</phase>
更改为<phase>test</phase>
,以便 mvn:test 生成jacoco报告(而不仅仅是万无一失的报告)。<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.ut.arg</propertyName>
</configuration>
</execution>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jacoco.agent.ut.arg}</argLine>
</configuration>
</plugin>