简体   繁体   English

Jacoco 如何正确排除包

[英]Jacoco how to correctly exclude package

I am using the Jacoco Maven plugin version 0.8.1 (With Java 8 / Maven 3.1.0).我正在使用 Jacoco Maven 插件版本 0.8.1(使用 Java 8 / Maven 3.1.0)。 Cannot get Jacoco to work with path exclusions.无法让 Jacoco 使用路径排除。 I would like to exclude these packages :我想排除这些包:

  • my.package.model
  • my.package.exception

What I tried :我试过的:

<build>
      <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>  
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>my.package.model</exclude>
                        <exclude>my.package.exception</exclude>
                    </excludes>
                </configuration>
            </plugin>
      </plugins>
</build>

<reporting>
        <plugins>
             <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <configuration>
                    <excludes>
                        <exclude>my.package.model</exclude>
                        <exclude>my.package.exception</exclude>
                    </excludes>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
</reporting>

And also (for the excludes part) :而且(对于excludes部分):

<excludes>
     <exclude>my.package.model**</exclude>
     <exclude>my.package.exception**</exclude>
</excludes>

<excludes>
     <exclude>my/package/model/**/*</exclude>
     <exclude>my/package/exception/**/*</exclude>
</excludes>

<excludes>
     <exclude>*/my/package/model/**/*</exclude>
     <exclude>*/my/package/exception/**/*</exclude>
</excludes>

<excludes>
     <exclude>**/my/package/model/**/*</exclude>
     <exclude>**/my/package/exception/**/*</exclude>
</excludes>

<excludes>
     <exclude>**/my/package/model/**</exclude>
     <exclude>**/my/package/exception/**</exclude>
</excludes>

<excludes>
     <exclude>**/my/package/model/*</exclude>
     <exclude>**/my/package/exception/*</exclude>
</excludes>

<excludes>
     <exclude>**/model/*</exclude>
     <exclude>**/exception/*</exclude>
</excludes>

<excludes>
     <exclude>**/model**</exclude>
     <exclude>**/exception**</exclude>
</excludes>

Impossible to remove these packages from the final report ... Frustrating.不可能从最终报告中删除这些包......令人沮丧。

I read :我读 :

Nothing work.没有任何作用。

Any idea ?任何的想法 ?

I have that and it works (notice that the excludes are in execution/configuration and that everything is in pluginManagement ):我有它并且它可以工作(注意excludesexecution/configuration并且一切都在pluginManagement ):

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>prepare-agent-integration</goal>
                    </goals>
                    <configuration>
                        <destFile>${project.build.directory}/integration-coverage-reports/jacoco-it.exec</destFile>
                        <excludes>
                            <exclude>weblogic/*</exclude>
                        </excludes>
                    </configuration>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${project.build.directory}/integration-coverage-reports/jacoco-it.exec</dataFile>
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                        <excludes>
                            <exclude>my/company/package/db/entity/**/*.class</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

As per the example that you have shared, this change in the POM file should work:根据您共享的示例,POM 文件中的此更改应该起作用:

<build>
      <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>  
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>my/package/model/**/*.class</exclude>
                        <exclude>my/package/exception/**/*.class</exclude>
                    </excludes>
                </configuration>
            </plugin>
      </plugins>
</build>

<reporting>
        <plugins>
             <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <configuration>
                    <excludes>
                        <exclude>my/package/model/**/*.class</exclude>
                        <exclude>my/package/exception/**/*.class</exclude>
                    </excludes>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
</reporting>

I usually put the prepare-agent goal and report goal inside the same plugin.我通常将prepare-agent目标和report目标放在同一个插件中。 This helps me to put the exclude packages under one section only.这有助于我将排除包仅放在一个部分下。 This is how my pom file looks:这是我的 pom 文件的样子:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.1</version>

            <configuration>
                <excludes>
                    <exclude>my/package/model/**/*.class</exclude>
                    <exclude>my/package/exception/**/*.class</exclude>
                </excludes>
            </configuration>

            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>  
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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