You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Maven+Spring Boot项目Jacoco无输出问题求助

多模块Maven项目Jacoco覆盖率报告生成问题

我们有如下结构的多模块Java Maven项目:

parent
├── child-1
├── child-2
└── common

父模块无代码,代码和测试主要集中在common模块。我们需要为每个子模块生成独立的代码覆盖率报告(而非全局统一报告)。

按照SonarQube Java测试覆盖率文档,我们在父POM的coverage profile中添加了对应配置,但运行mvn clean verify时日志提示“缺少执行数据文件”,父模块及所有子模块均未生成XML报告、.exec文件和target/site/jacoco目录。

运行mvn clean verify sonar:sonar或在Bitbucket Sonar流水线中执行时,同样出现类似提示,子模块target目录无相关输出。我们已尝试添加phase配置、指定output为file、激活coverage profile运行Sonar扫描等操作,均未解决问题。以下是完整的父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 
                             https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.4</version>
    </parent>

    <properties>
        <sonar.organization>xxx</sonar.organization>
        <sonar.host.url>https://sonarcloud.io</sonar.host.url>
    </properties>

    <groupId>com.xx.xx</groupId>
    <artifactId>xx-xx-service</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>xx-xx-service</name>
    <description>xx service</description>
    <packaging>pom</packaging>

    <modules>
        <module>xx-common</module>
        <module>xx-api</module>
        <module>xx-schedule</module>
    </modules>

    <profiles>
        <profile>
            <id>coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.13</version>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <formats>
                                        <format>XML</format>
                                    </formats>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

作为Jacoco新手,我们原本期望Sonar能处理覆盖率报告,但按文档配置后未生效,请问下一步该如何操作?

内容的提问来源于stack exchange,提问作者John Little

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 20:42:45