2

I am using maven-jacoco-plugin for generating the test coverage. Version used is 0.8.7.

When running the mvn test command, it's generating the report in exec format.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco-maven-plugin.version}</version>
    <configuration>
        <formats>XML</formats>
    </configuration>
    <executions>
        <!-- Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when Maven
            the Surefire plugin is executed. -->
        <execution>
            <id>jacoco-initialize-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
                <goal>report</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/../target/site/jacoco-aggregate</outputDirectory>
                <!--<destFile>${project.build.directory}/../../target/coverage-reports/jacoco-ut.exec</destFile>-->
                <append>true</append>
                <propertyName>jacoco.agent.argLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-initialize-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>${project.build.directory}/../../target/coverage-reports/jacoco-it.exec</destFile>
                <append>true</append>
                <propertyName>jacoco.agent.argLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-merge</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>merge</goal>
            </goals>
            <configuration>
                <fileSets>
                    <fileset>
                        <directory>${project.build.directory}/../../target/coverage-reports/</directory>
                        <includes>
                            <include>*.exec</include>
                        </includes>
                    </fileset>
                </fileSets>
                <destFile>${project.build.directory}/../../target/coverage-reports/jacoco.exec</destFile>
            </configuration>
        </execution>
        <!-- Ensures that the code coverage report for integration tests is created after all tests have been
            run. -->
        <execution>
            <id>jacoco-report</id>
            <phase>verify</phase>
            <goals>
                <goal>report-aggregate</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/../target/site/jacoco-aggregate</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

When I tried adding in configuration tag under using XML, it's giving an error as

Unable to parse configuration of mojo org.jacoco:jacoco-maven-plugin:0.8.8:report-aggregate for parameter formats: Cannot assign configuration entry 'formats' with value 'XML' of type java.lang.String to property of type java.util.List -> [Help 1]

Can anyone please suggest how to move forward on this?

2
  • 1
    I wonder if maybe it should be <formats><format>XML</format></formats> or something like that, but I can't try it out right now. Commented Jul 15, 2022 at 14:02
  • Thanks it worked but its generating XML which is not readable perhaps it dumped exec data into xml file Commented Jul 15, 2022 at 14:29

1 Answer 1

0

You must add a format node:

<formats>
    <format>XML</format>
</formats>

On GitHub you can find examples. Like this: https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-report-select-formats/pom.xml

Sign up to request clarification or add additional context in comments.

1 Comment

its not working even after adding in formats as XML since reason being there are intermdeiate steps where the format is defined as exec

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.