pdf - 如何使用Maven PDF插件从Surefire Report生成PDF?

标签 pdf report maven-surefire-plugin maven-site-plugin maven-pdf-plugin

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

./target/site/surefire-report.html

我知道有一个Maven PDF插件可以生成PDF文件(http://maven.apache.org/plugins/maven-pdf-plugin/surefire-report.html)。但我没能让它发挥作用。我将其包含在我的 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>

当我尝试运行它时,出现错误,指出某些源目录不存在:

  ...
  [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 的源文件?

最佳答案

将我的报告添加到 pdf 中没有任何问题:

<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>
<build>
    <extensions>
        <!-- Enabling the use of FTP -->
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ftp</artifactId>
            <version>2.2</version>
        </extension>
    </extensions>

    <plugins>
        <!-- Génération d'un PDF à l'identique du site maven -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pdf-plugin</artifactId>
            <executions>
                <execution>
                    <id>pdf</id>
                    <phase>site</phase>
                    <goals>
                        <goal>pdf</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <!-- Gestion des plugins pour ce projet et ses sous modules -->
    <pluginManagement>
        <plugins>
            <!-- Indication de compilation sur la version de Java à utiliser -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>


            <!-- Gestion du tagage des releases -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.2.2</version>
                <configuration>
                    <tagBase>http://svn.xxx.fr.sopra/corprepo/svn/myproject/repository/tags/</tagBase>
                    <scmCommentPrefix>[DEV#GCL]</scmCommentPrefix>
                </configuration>
            </plugin>

            <!-- Gestion de la fabrication du site maven -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <locales>fr</locales>
                    <outputEncoding>UTF-8</outputEncoding>
                </configuration>
            </plugin>
            <!-- Génération d'un PDF à l'identique du site maven -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pdf-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>pdf</id>
                        <phase>site</phase>
                        <goals>
                            <goal>pdf</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </pluginManagement>
</build>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - Reporting & GCL - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.8.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <configLocation>/src/main/config/checkstyle-sopra.xml</configLocation>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.12</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>2.7.1</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.3</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.4</version>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>summary</report>
                        <report>modules</report>
                        <report>project-team</report>
                        <report>mailing-list</report>
                        <report>cim</report>
                        <report>issue-tracking</report>
                        <report>license</report>
                        <report>scm</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

还有我的 src/main/pdf.xml

<document xmlns="http://maven.apache.org/DOCUMENT/1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DOCUMENT/1.0.1 http://maven.apache.org/xsd/document-1.0.1.xsd"
outputName="${project.artifactId}">

     <meta>
      <title>Maven PDF Plugin</title>
      <author>The Apache Maven Project</author>
 </meta>

 <toc name="Table of Contents">
      <item name="Introduction" ref="index.apt"/>

 </toc>

 <cover>
      <coverTitle>${project.name}</coverTitle>
      <coverSubTitle>v. ${project.version}</coverSubTitle>
      <coverType>User Guide</coverType>
      <projectName>${project.name}</projectName>
      <projectLogo>images/logo_myorg.png</projectLogo>
      <companyName>${project.organization.name}</companyName>
      <companyLogo>images/logo_myorg.png</companyLogo>
 </cover>

由于保密政策,我无法向您提供 PDF,但它工作正常:)

关于pdf - 如何使用Maven PDF插件从Surefire Report生成PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920842/

相关文章:

java - 在 Java 中从 PDF 生成 PCL

maven - 如何让 maven cobertura 和 surefire 插件一起工作?

javascript - 在网页上嵌入 PDF 并水平滚动使其居中

javascript - Apache PDF 数字签名

php - 在新标签页中从 FPDF 打开 PDF

java - 如何定制测试报告?

report - 如何分析 JMeter 摘要报告?

delphi - 最有用的 Delphi TStringGrid (Grid) 替代品推荐

java - 如何在Logback中定义一个具有默认值的变量并覆盖它?

Maven不会运行测试