Jacoco Plugin与maven集成

时间:2015-01-22 10:38:53

标签: java maven jacoco

执行maven(mvn clean install)时出现以下错误

无法执行目标org.jacoco:jacoco-maven-plugin:0.7.2.201409121644 :项目testng上的prepare-agent(默认):目标org.jacoco的执行默认值 :jacoco-maven-plugin:0.7.2.201409121644:prepare-agent失败:无法加载  插件中的mojo'prepare-agent''org.jacoco:jacoco-maven-plugin:0.7.2.201409 121644' 。缺少必需的类:org / jacoco / core / runtime / AgentOptions

请找到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>

2 个答案:

答案 0 :(得分:0)

尝试使用新版本的 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>

答案 1 :(得分:0)

我说如下:

<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>