Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

maven - Jacoco doesn't produce coverage reports

I 'm using maven-sure fire plugin to execute tests and Jacoco plugin to generate the coverage reports. Jacoco does't provide coverage reports and instead fails with the debug log as shown here under.

[INFO] --- jacoco-maven-plugin:0.8.0:report (jacoco-site) @ util --- [INFO] Skipping JaCoCo execution due to missing execution data file.

Here is how the maven sure-fire plugin looks.

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <parallel>classes</parallel>
                     <threadCount>8</threadCount>
                     <forkCount>4</forkCount>
                     <encoding>UTF-8</encoding>
                    <inputEncoding>UTF-8</inputEncoding>
                    <outputEncoding>UTF-8</outputEncoding>
                    <argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                        -Dfile.encoding=UTF-8</argLine>
                     </configuration>
            </plugin>

Here is how the Jacoco plugin looks like.

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <configuration>
                    <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>package</phase>
                        <goals>
                        <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Quoting http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :

If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.

One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine} -your -extra -arguments</argLine>
  </configuration>
</plugin>

Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:

<properties>
  <argLine>-your -extra -arguments</argLine>
</properties>
...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- no argLine here -->
  </configuration>
</plugin>

so either define

<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>

as property:

<build>
  <properties>
    <argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>
  </properties>
...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.10</version>
    <configuration>
      <!-- no argLine here -->

or add @{argLine} to it:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <argLine>@{argLine} -Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...