4

我想以某种方式使用 Jacoco,以便将 aSample.java class从整体覆盖范围中排除。为了实现这一点,我已将目标包含<exclude>prepare-agentmaven pom.xml 中

Jacoco 插件:

                <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.1.201405082137</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

Surefire 插件:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
            <configuration>
                <excludes>
                    <exclude>**/*Sample.java</exclude>
                </excludes>
            </configuration>
        </plugin>

属性部分:

    <properties>
    <argLine>-Dfile.encoding=ISO-8859-1</argLine>
</properties>
4

2 回答 2

7

这是为 JaCoCo 配置排除/包含的正确方法:

    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.1.201405082137</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>
                    <exclude>**/*Sample.class</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
        </plugin>
    </plugins>

有关更多详细信息,您可以浏览此文档: http ://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html

于 2017-08-11T07:14:42.143 回答
2

这是我的解决方案,请注意排除类模式是class.path.className.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
            <haltOnFailure>true</haltOnFailure>
            <rules>
                <rule>
                    <element>CLASS</element>
                    <excludes>
                        <exclude>com.example.className</exclude>
                        <exclude>com.example.config.*</exclude>
                    </excludes>
                    <limits>
                        <limit>
                            <counter>LINE</counter>
                            <value>COVEREDRATIO</value>
                            <minimum>0.80</minimum>
                        </limit>
                    </limits>
                </rule>
            </rules>
            </configuration>
         </execution>
     </executions>
 </plugin>

对于配置细节,请查看此文档,希望对您有所帮助。

于 2020-09-02T23:13:36.727 回答