ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java – 使用report-aggregate报告和合并多模块jacoco报告

2019-09-10 16:00:39  阅读:2097  来源: 互联网

标签:jacoco java code-coverage jacoco-maven-plugin


尝试获取一个jacoco报告,该报告将显示来自多个模块的所有结果.

我能够看到每个子模块在构建项目后都有一个jacoco.exec但不确定如何让它输出一个报告,该报告将包含每个模块的所有结果.

这是我在Root pom.xml中包含的内容:

                <plugin>
                    <groupId>@project.groupId@</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>@project.version@</version>
                </plugin>



             <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

我出于报告目的明确创建了一个新模块. (例如report-aggregate-module)

删除了组ID并在此示例中使用了通用工件ID:

这是我在此报告聚合子模块的pom.xml中添加的内容:

<?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>
    <parent>
        <artifactId>report-aggregate</artifactId>
        <groupId>com.name.group</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <artifactId>report-aggregate</artifactId>
    <name>Report Aggregate</name>

    <properties>
        <wildfly.version>10.0.0.Final</wildfly.version>
        <wildfly.artifactId>wildfly-dist</wildfly.artifactId>
    </properties>

    <dependencies>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module1</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module2</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module3</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module4</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>report-aggregate</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

一切似乎编译好了,jacoco exec似乎没有为report-aggregate-module创建.任何人都知道这个解决方案,或者我做错了吗?

解决方法:

对不起,如果这是一个迟到的答案.

我假设你的root pom.xml是一个聚合器,< modules>由module1,module2和report-aggregate组成.这是您遇到麻烦的原因:由于您的root pom.xml是一个聚合器,它会在您的子模块执行之前运行JaCoCo,因此您的最终报告为空.你应该:

>将目标报告的配置 – jacoco-maven-plugin的聚合从根POM移动到报告聚合POM.这应该可以解决问题,因为您的报告聚合POM使用< dependencies>而不是< modules>.
>在根POM中保持jacoco-maven-plugin的目标prepare-agent的配置.

我建议你看一下JaCoCo论坛https://groups.google.com/forum/#!topic/jacoco/FpdLbxsXSTY.它指的是一个完整的演示集成测试https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate.

标签:jacoco,java,code-coverage,jacoco-maven-plugin
来源: https://codeday.me/bug/20190910/1799795.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有