如何使用 jacoco 从代码覆盖率计算中排除某些类?

问题描述 投票:0回答:1

我正在尝试为我的 Quarkus 应用程序检测代码覆盖率。

运行时

mvn clean install
一切正常,代码覆盖率按预期显示,并且类被排除。

但是运行时

mvn test
应该从覆盖率计算中排除的类却没有!

会出现什么错误?

我尝试过此配置,但它不起作用!

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.8</version>
                <executions>
                    <!-- Prepare agent -->
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>
                            <excludes>
                                <exclude>org/quarkus/configurations/**</exclude>
                            </excludes>
                            <destFile>${project.build.directory}/jacoco-quarkus.exec</destFile>
                            <append>true</append>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <excludes>
                                <exclude>org/quarkus/configurations/**</exclude>
                            </excludes>
                            <dataFile>${project.build.directory}/jacoco-quarkus.exec</dataFile>
                            <outputDirectory>${project.build.directory}/jacoco-report</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>check</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.build.directory}/jacoco-quarkus.exec</dataFile>
                            <excludes>
                                <exclude>org/quarkus/configurations/**</exclude>
                            </excludes>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0</minimum>
                                        </limit>
                                        <limit>
                                            <counter>BRANCH</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

quarkus jacoco jacoco-maven-plugin
1个回答
0
投票

您可以使用 quarkus,jacoco.excludes 配置属性。

© www.soinside.com 2019 - 2024. All rights reserved.