为什么 Jacoco 合并不包括文件?

问题描述

我有一个多模块 maven 项目,并尝试使用 Jacoco 生成聚合报告,并运行“聚合”检查。但是,我无法以任何可能的方式让 Jacoco 合并功能通过 maven 插件工作。 因此我尝试创建一个最小的示例,如下所示

该项目只包含三个文件,maven pom文件和两个Jacoco exec文件(之前生成的)

  • 文件
    • pom.xml
    • jacoco1.exec
    • jacoco2.exec

pom 文件内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>com.jacoco</groupId>
    <version>0.1-SNAPSHOT</version>
    <artifactId>coverage</artifactId>

    <name>Coverage report</name>
    <description>Coverage report module</description>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>merge-results</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${basedir}/}</directory>
                                    <includes>
                                        <include>*.exec</include> <!-- In the end,I tried a lot of different include options,but nothing seems to work -->
                                        <include>jacoco1.exec</include>
                                        <include>jacoco2.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

当我运行 mvn verify -X 时,我在合并目标下得到以下调试输出

[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.8.6:merge from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.8.6,parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.8.6:merge' with basic configurator -->
[DEBUG]   (f) destFile = /Users/rsn/git/coverage-mve/coverage/target/jacoco.exec
[DEBUG]   (s) directory = /Users/rsn/git/coverage-mve/coverage/}
[DEBUG]   (s) includes = [*.exec,jacoco1.exec,jacoco2.exec]
[DEBUG]   (f) fileSets = [org.apache.maven.shared.model.fileset.FileSet@56681eaf]
[DEBUG]   (f) project = MavenProject: com.jacoco:coverage:0.1-SNAPSHOT @ /Users/rsn/git/coverage-mve/coverage/pom.xml
[DEBUG]   (f) skip = false
[DEBUG] -- end configuration --
[INFO] Skipping JaCoCo merge execution due to missing execution data files

Maven 版本是

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.8.0_181,vendor: Oracle Corporation,runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre
Default locale: en_DK,platform encoding: UTF-8
OS name: "mac os x",version: "10.16",arch: "x86_64",family: "Mac"

我尝试下载 jacococli.jar 并手动合并文件效果很好。我想这可以作为解决方法下载并使用 maven ant run 插件运行,但我更喜欢只使用该插件

任何可能导致此问题的想法?

解决方法

你的

<fileSet>
  <directory>${basedir}/}</directory>

看起来很可疑 - 请注意尾随大括号,它可能被解释为目录名称。