【问题标题】:Jacoco report-aggregate - Include report of aggregate projectJacoco report-aggregate - 包括聚合项目的报告
【发布时间】:2019-05-27 18:33:58
【问题描述】:

我有一个多模块 Maven 项目。

parent
   child1
   child2
   child3-report

所有子项目都有单元测试,child3 依赖于child1child2。跟随 child3 的 pom

<plugin>
     <groupId>org.jacoco</groupId>
     <artifactId>jacoco-maven-plugin</artifactId>
     <version>0.8.2</version>
     <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
                <goal>report-aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

生成的 jacoco 聚合报告仅包括 child1 和 child2 的报告,但不包括 child3。如何解决这个问题?

不想仅为报告创建第四个子模块。

【问题讨论】:

    标签: java maven junit jacoco jacoco-maven-plugin


    【解决方案1】:

    我所做的是添加一个报告目标以包含模块本身的报告。

    <execution>
      <id>report-unit-tests</id>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
    

    【讨论】:

      【解决方案2】:

      在 jacoco github repo 上提出了多个与此功能相关的问题 (https://github.com/jacoco/jacoco/issues/812)。少数人可能会接受仅用于报告的单独模块,但更好的方法是使用一些可配置的标志来解决此问题。

      还有一个待处理的 PR (https://github.com/jacoco/jacoco/pull/1007)。

      【讨论】:

        【解决方案3】:

        我在为 Maven 项目实施 Jacoco 时遇到了同样的问题。 不幸的是,恐怕唯一的解决方案是在 Maven 项目中添加一个新的子模块。 您应该将依赖项放入您的 3 个子模块和报告聚合目标。 所以,你应该有类似下面的配置:

        parent --> Goal: Prepare agent
           child1 --> Goal: report
           child2 --> Goal: report
           child3-report --> Goal: report
           child4-Aggregator --> Goal: report-aggregate
        

        在您的父 pom.xml 中,您应该添加 child4-Aggregator 模块作为要运行的最后一个模块。

        【讨论】:

          【解决方案4】:

          也许你可以试试这个: 在 child3 的 pom.xml 中添加 child3 本身

          <dependency>
          <groupId>XXXX</groupId>
          <artifactId>child3</artifactId>
          </dependency>
          

          【讨论】:

            猜你喜欢
            • 2020-06-28
            • 2018-11-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-06-27
            • 2022-06-14
            • 2017-03-04
            相关资源
            最近更新 更多