jacoco合并目标无法找到子模块的数据文件

时间:2017-02-01 19:42:12

标签: java maven jacoco jacoco-maven-plugin

我有一个基于PowerMock的单元测试的大型Maven多项目构建。我正在生成一个" target / jacoco.exec"在子模块中,在子模块的整体父pom中使用插件配置。我有一个额外的子模块,它只使用" report-aggregate",并指定各种子模块作为依赖项。这一切基本上都有效。

我现在正试图将此数据与SonarQube集成。似乎安装的SonarQube Java Analyzer版本不知道如何处理多个jacoco.exec文件,它只处理一个文件。所以,我试图让"合并"工作的目标。我阅读了有关此目标的文档,但我显然没有正确执行某些操作,因为它只是找不到数据文件。

在我使用" report-aggregate"的同一个子模块中,我执行了以下操作:

         <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.8</version>
            <executions>
                <execution>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                </execution>
                <execution>
                   <id>merge</id>
                   <goals>
                       <goal>merge</goal>
                   </goals>
                   <configuration>
                       <fileSets>
                           <fileSet>
                               <directory>../childmodule1/target</directory>
                               <include>*.exec</include>
                           </fileSet>
                           <fileSet>
                               <directory>../childmodule2/target</directory>
                               <include>*.exec</include>
                           </fileSet>
                           ... several more
                       </fileSets>
                   </configuration>
                </execution>
            </executions>
        </plugin>

当我跑&#34; mvn clean install&#34;从顶层开始,它最终处理了&#34; jacoco-aggregate&#34;子模块,并产生以下输出:

[INFO] ------------------------------------------------------------------------
[INFO] Building jacoco-aggregate 2.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jacoco-aggregate ---
[INFO] Deleting ...\jacoco-aggregate\target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:merge (merge) @ jacoco-aggregate ---
[INFO] Skipping JaCoCo merge execution due to missing execution data files
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (filter) @ jacoco-aggregate ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory ...\jacoco-aggregate\src\main\resources
[INFO] 
[INFO] --- depends-maven-plugin:1.2:generate-depends-file (generate-depends-file) @ jacoco-aggregate ---
[INFO] Created: ...\jacoco-aggregate\target\classes\META-INF\maven\dependencies.properties
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:instrument (default-instrument) @ jacoco-aggregate ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:restore-instrumented-classes (default-restore-instrumented-classes) @ jacoco-aggregate ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:report (default-report) @ jacoco-aggregate ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- maven-javadoc-plugin:2.10.4:jar (module-javadoc-jar) @ jacoco-aggregate ---
[INFO] Not executing Javadoc as the project is not a Java classpath-capable package
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:report-aggregate (report-aggregate) @ jacoco-aggregate ---
[INFO] Loading execution data file ...\childmodule1\target\jacoco.exec
[INFO] Loading execution data file ...\childmodule2\target\jacoco.exec
... several more
[INFO] Analyzed bundle 'childmodule1' with 1 classes
[INFO] Analyzed bundle 'childmodule2' with 1 classes

正如您所看到的,它执行了&#34; merge&#34;目标,但它没有找到任何数据文件,即使后来的&#34;报告 - 聚合&#34;目标确实。

所以我假设我指定文件集的方式或与之相关的东西在某种程度上是错误的。这可能有什么问题?

3 个答案:

答案 0 :(得分:2)

我有两个问题,就是我如何指定&#34; merge&#34;目标:

  • &#34;合并&#34;的默认阶段是&#34;生成资源&#34;。我无法想象它是如何有用的,因为我不知道在这个阶段之前如何创建这些数据文件。我将其更改为&#34;验证&#34;而且效果更好。

  • 在文件集中,我指定了相对于此子模块的目录路径,当我应该相对于项目的根目录指定它们时。我删除了&#34; ../"从那些路径,这解决了这个问题。

答案 1 :(得分:1)

尝试将Deque(以及<fileSets>,如果有的话)移至<destFile/>而不是<plugin><configuration>

<execution><configuration>

答案 2 :(得分:0)

我的配置略有不同,因为我有一个报告子模块,该模块应处理所有其他模块,既不是子模块也不是兄弟姐妹,而是表兄弟。我最终遇到了一个配置问题:

                <fileSets>
                    <fileSet>
                        <directory>${project.build.directory}/../../../</directory>
                        <includes>
                            <include>**/*.exec</include>
                        </includes>
                    </fileSet>
                </fileSets>

执行以下操作可以帮助调查配置问题:

mvn org.jacoco:jacoco-maven-plugin:merge -X

但是,正如另一个答案所建议的那样,它需要将配置从执行块移动到主插件配置。