简体   繁体   中英

Jacoco Plugin integration with maven

Following error occured whlile executing maven(mvn clean install)

Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.2.201409121644 :prepare-agent (default) on project testng: Execution default of goal org.jacoco :jacoco-maven-plugin:0.7.2.201409121644:prepare-agent failed: Unable to load the mojo 'prepare-agent' in the plugin 'org.jacoco:jacoco-maven-plugin:0.7.2.201409 121644'. A required class is missing: org/jacoco/core/runtime/AgentOptions

Please find the pom

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
    <execution>
        <id>jacoco-initialize</id>
        <phase>initialize</phase>
        <goals>
            <goal>prepare-agent</goal>
        </goals>
    </execution>
    <execution>
        <id>jacoco-site</id>
        <phase>package</phase>
        <goals>
            <goal>report</goal>
        </goals>
    </execution>
</executions>
</plugin>

Try with the new version of jacoco-maven-plugin :

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.1</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I put as below:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <configuration>
        <target>
            <propertyfile file="lombok.config">
                <entry key="config.stopBubbling" value="true" />
                <entry key="lombok.addLombokGeneratedAnnotation" value="true" />
            </propertyfile>
        </target>
        <excludes>
            <exclude>**/domain/**</exclude>
            <exclude>**/enumeration/**</exclude>
            <exclude>**/exception/**</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <!-- attached to Maven test phase -->
        <execution>
            <id>report</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <!-- Add this checking -->
        <execution>
            <id>jacoco-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <rules>
                    <rule>
                        <element>PACKAGE</element>
                        <limits>
                            <limit>
                                <counter>INSTRUCTION</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>65%</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM