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
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]
...
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?
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.
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.
I don't have any problem including my report into 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>
And my 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>
I can't give you the PDF because of confidential policy, but it works fine :)
来源:https://stackoverflow.com/questions/4920842/how-to-us-maven-pdf-plugin-to-generate-pdf-from-surefire-report