JaCoCo 没有忽略 class
JaCoCo not ignoring class
我已成功将 JaCoCo 添加到我的项目中,它工作正常,但出于某种原因它不允许我排除 class:src/main/java/com/example/Main.java
<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>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<skip>false</skip>
<haltOnFailure>true</haltOnFailure>
<rules>
<rule>
<element>BUNDLE</element>
<excludes>
<exclude>com/example/Main.*</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
我已经尝试了该站点中的其余问题,但在排除 单个 class 时,其中 none 对我有用.执行上面的代码后,我得到以下输出,其中包含 class Main,这是我想避免的:
提前致谢
在你的问题中,excludes
块是在 configuration/rules
中声明的。它应该在 configuration
.
内声明
例如:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<excludes>
<exclude>**/Main.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
我建议从最简单的插件定义(即我在上面发布的内容)开始,一旦它起作用,将其扩展到(1)通过包名称引用 class 和(2)添加你的规则。
我已成功将 JaCoCo 添加到我的项目中,它工作正常,但出于某种原因它不允许我排除 class:src/main/java/com/example/Main.java
<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>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<skip>false</skip>
<haltOnFailure>true</haltOnFailure>
<rules>
<rule>
<element>BUNDLE</element>
<excludes>
<exclude>com/example/Main.*</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
我已经尝试了该站点中的其余问题,但在排除 单个 class 时,其中 none 对我有用.执行上面的代码后,我得到以下输出,其中包含 class Main,这是我想避免的:
提前致谢
在你的问题中,excludes
块是在 configuration/rules
中声明的。它应该在 configuration
.
例如:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<excludes>
<exclude>**/Main.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
我建议从最简单的插件定义(即我在上面发布的内容)开始,一旦它起作用,将其扩展到(1)通过包名称引用 class 和(2)添加你的规则。