我们如何使用Maven PDF插件从Surefire报表生成PDF? [英] How to us Maven PDF Plugin to generate PDF from Surefire Report?

查看:123
本文介绍了我们如何使用Maven PDF插件从Surefire报表生成PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行JUnit测试后,我使用Maven Surefire报告插件(http://maven.apache.org/plugins/maven-surefire-report-plugin/)生成HTML测试报告.这将导致以下文件:

after running my JUnit tests I use the Maven Surefire Report plugin (http://maven.apache.org/plugins/maven-surefire-report-plugin/) to generate a HTML test report. This results in the following file:

./target/site/surefire-report.html

我知道有一个Maven PDF插件可以生成PDF文件(http://maven.apache.org/plugins/maven-pdf-plugin/surefire-report.html).但是我无法使其正常运行.我将其包含在pom.xml中:

I know that there is a Maven PDF plugin to generate PDF files (http://maven.apache.org/plugins/maven-pdf-plugin/surefire-report.html). But I don't manage to get it working. I included it in my pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-pdf-plugin</artifactId>
  <executions>
    <execution>
      <id>pdf</id>
      <phase>test</phase>
      <goals>
        <goal>pdf</goal>
      </goals>
      <configuration>
        <outputDirectory>/tmp</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

当我尝试运行它时,我得到一个错误,提示某些源目录不存在:

When I try to run it I get an error that some source directory doesn't exist:

  ...
  [mvn] [INFO] [pdf:pdf {execution: default-cli}]
  [mvn] [INFO] ------------------------------------------------------------------------
  [mvn] [INFO] Building VB Common
  [mvn] [INFO]    task-segment: [pdf:pdf]
  [mvn] [INFO] ------------------------------------------------------------------------
  [mvn] [INFO] [pdf:pdf {execution: default-cli}]
  [mvn] [INFO] ------------------------------------------------------------------------
  [mvn] [ERROR] BUILD ERROR
  [mvn] [INFO] ------------------------------------------------------------------------
  [mvn] [INFO] Error during document generation: Source directory doesn't exists (/home/user/myproject/src/site).
  [mvn]
  ...

该错误并不令人惊讶,因为我没有./src/site文件夹. 但是,如何配置PDF插件,以便它将来自./target/site/surefire-report.html的HTML报告作为PDF的源文件?

The error is not so surprising as I don't have a ./src/site folder. But how can I configure the PDF plugin so it takes my HTML report from ./target/site/surefire-report.html as source file for the PDF?

推荐答案

来自文档,该插件需要一个file that contains the DocumentModel of the PDF to generate.,默认情况下是src/site/pdf.xml,这就是为什么该插件在找不到此文件时会失败的原因.

From the documentation of maven pdf plugin, the plugin needs a file that contains the DocumentModel of the PDF to generate. It is by default src/site/pdf.xml, which is why the plugin fails when it does not find this file.

该插件旨在生成由Maven网站插件生成的报告的pdf版本.这样,它会为该项目生成所有报告的pdf版本,如果已配置,其中将包括surefire-report.

The plugin is intended to generate the pdf version of the report generated by the maven site plugin. As such, it generates the pdf versions of all reports for the project, which would include the surefire-report, if configured.

这篇关于我们如何使用Maven PDF插件从Surefire报表生成PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆