如何从 Jacoco 覆盖范围中排除一个类?

mea*_*our 3 cobertura maven jenkins jacoco jacoco-maven-plugin

我想以某种方式使用 Jacoco,以便它Sample.java class从整体覆盖范围中排除 a 。为了实现这个目标我已经包括<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>
Run Code Online (Sandbox Code Playgroud)

万能插件:

            <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>
Run Code Online (Sandbox Code Playgroud)

属性部分:

    <properties>
    <argLine>-Dfile.encoding=ISO-8859-1</argLine>
</properties>
Run Code Online (Sandbox Code Playgroud)

Stu*_*rma 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>
Run Code Online (Sandbox Code Playgroud)

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

  • 应该是 Sample.class 不是 Sample.java &lt;configuration&gt; &lt;excludes&gt; &lt;exclude&gt;**/*Sample.class&lt;/exclude&gt; &lt;/excludes&gt; &lt;/configuration&gt; (6认同)