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

如何修改Surefire HTML报告的页面顶部标题?

修改Maven Surefire HTML报告的页面标题

Maven Surefire Report插件没有直接提供配置项修改报告顶部的“Surefire Report”标题,但可以通过自定义Velocity模板实现这个需求,具体步骤如下:

  1. 复制默认模板到项目资源目录
    将Surefire插件内置的Velocity模板 org/apache/maven/plugins/surefire/report/surefire-report.vm 从插件jar包中提取出来,复制到项目的 src/main/resources/surefire 目录下(目录不存在则手动创建)。

  2. 修改模板中的标题内容
    打开复制的 surefire-report.vm 文件,找到两处标题相关的代码:

  • 页面顶部的标题标签:<h1>Surefire Report</h1>
  • HTML页面的title标签:<title>Surefire Report</title>

将这两处的Surefire Report替换为你的自定义文本,比如和文件名一致的Results-${env} Environment。

  1. 在插件配置中指定自定义模板
    更新maven-surefire-report-plugin的配置,添加reportTemplate参数指向自定义模板的路径:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-report-plugin</artifactId>
    <version>3.0.0-M7</version>
    <configuration>
        <outputName>Results-${env} Environment</outputName>
        <!-- 指定自定义Velocity模板路径 -->
        <reportTemplate>${project.basedir}/src/main/resources/surefire/surefire-report.vm</reportTemplate>
    </configuration>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>report-only</goal>
            </goals>
        </execution>
    </executions>
</plugin>

补充说明

  • 如果需要动态替换标题(比如使用环境变量),确保模板中使用的Maven属性(如${env})在构建时能被正确解析。
  • 验证模板路径是否正确,${project.basedir}代表项目的根目录。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 00:15:36