我想排除某些类文件,因为这些文件在计算代码覆盖范围时不想考虑。
我的情况是,我从Jenkins获取.EXEC文件和类文件,以进行多个项目,并尝试创建一个汇总报告。因此,我正在使用Jacoco:合并来创建合并的EXEC文件,并且使用Jacoco:Report生成报告。我想在这里排除一些课程。但是我不能在jacoco内使用<excludes>
:结构。
我的代码附加在这里。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wso2</groupId>
<artifactId>code-coverage-report</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<directory>${project.basedir}/target</directory>
</build>
<profiles>
<profile>
<id>with-tests</id>
<activation>
<property>
<name>!maven.test.skip</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-jacoco-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<includeTypes>jar</includeTypes>
<includeArtifactIds>org.jacoco.ant</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<!-- Ant plugin - Merge Jacoco Reports -->
<!-- Logging and distribution modules are not checked since not relevant -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:jacoco="antlib:org.jacoco.ant">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${project.build.directory}"/>
</taskdef>
<jacoco:merge destfile="merged.exec">
<fileset dir="jacoco/exec/" includes="*.exec"/>
</jacoco:merge>
<jacoco:report>
<executiondata>
<file file="merged.exec"/>
</executiondata>
<structure name="Final Coverage Report">
<classfiles>
<fileset dir="jacoco/class/classes/"/>
</classfiles>
<excludes>
**/org/xxx/carbon/dataservices/ui/stub/admin/*,
**/org/xxx/carbon/rest/api/stub/types/aaa/*,
**/org/xxx/carbon/endpoint/stub/types/aaa/*,
</excludes>
</structure>
<html destdir="jacoco/tmp_report"/>
<xml destfile="jacoco/tmp_report/coverage-report.xml"/>
<csv destfile="jacoco/tmp_report/coverage-report.csv"/>
</jacoco:report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jacoco.version>0.7.9</jacoco.version>
</properties>
</project>
但给出以下例外。当我尝试运行它时。
An Ant BuildException has occured: structure doesn't support the nested "excludes" element.
请参阅文档:
任务报告
元素结构
请注意,
classfiles
和sourcefiles
元素接受任何ANT资源收集。因此,还可以过滤类文件集,并允许缩小报告范围的范围,例如:<classfiles> <fileset dir="classes"> <include name="org/jacoco/examples/important/**/*.class"/> </fileset> </classfiles>
因此
<classfiles>
<fileset dir="jacoco/class/classes/">
<exclude name="org/xxx/carbon/dataservices/ui/stub/admin/**/*.class"/>
<exclude name="org/xxx/carbon/rest/api/stub/types/aaa/**/*.class"/>
<exclude name="org/xxx/carbon/endpoint/stub/types/aaa/**/*.class"/>
</fileset>
</classfiles>