7

I have a maven project with jacoco plugin, which generates reports in different formats, such as html, csv and xml. But I need only html. How can I specify it?

Here is some code, where I add jacoco plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    //other plugins
    </plugins>
</build>

Then I run tests:

mnv clean test

And all reports appears in "target" directory.

I read documentation https://www.eclemma.org/jacoco/trunk/doc/maven.html, but I didn't found anything about how to pick requiring format. I found it only for Ant and Gradle.

I suppose I missing something, so I will be grateful for any clue.

Viktoria
  • 73
  • 1
  • 1
  • 4

3 Answers3

6

You can specify the report format to generate by specifying the configuration as follows-

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.7</version>
  <configuration>
    <!-- Rest of your configuration, if any -->
    <formats>HTML</formats>
  </configuration>
</plugin>

Note that this is available since version 0.8.7. Useful resource- https://www.jacoco.org/jacoco/trunk/doc/report-integration-mojo.html#formats

Gaurav Singh
  • 57
  • 1
  • 4
5

I searched the same thing and stumbled over the following issue with it: The old path was

target\jacoco\jacoco.report

The XML report however is put into:

target\site\jacoco

and in there are the XML, csv, html ...

Lonzak
  • 9,334
  • 5
  • 57
  • 88
3

As of today report goal of jacoco-maven-plugin unconditionally generates XML, HTML and CSV - see https://github.com/jacoco/jacoco/issues/9

And in my opinion there is no reasons to disable HTML and XML - cost of generation is small, developers can view HTML in place, while XML consumed by other tools such as SonarQube or Jenkins.

As a workaround if highly needed, report task of JaCoCo Ant Tasks can be executed via maven-antrun-plugin.

Godin
  • 9,801
  • 2
  • 39
  • 76