Convert Maven Site Software Documentation to PDF - pdf

I am currently working on a project written in Java and I am using Maven and the maven-site-plugin to generate a website containing all the relevant JavaDoc, reports, etc. I am needing at the same time to be able to convert the same documentation into a readable, book-like format. Are there any scripts or tools out there designed to take a website, and convert it into a reasonably formatted PDF or other style so that it can be easily given digitally or printed out?

The maven-pdf-plugin generates a PDF of the project documentation.
Two notes from the documentation to consider:
Note 1: By default, the PDF plugin generates a PDF document which aggregates all your site documents. If you want to generate each site document individually, you need to add -Daggregate=false in the command line.
Note 2: By default, the PDF plugin uses the FOP implementation. The plugin also supports the iText implementation, you just need to add -Dimplementation=itext in the command line.
You can actually specify the aggregate property in your POM (see example below).
This configuration will generate the PDF on each build that the docs profile is active (you could do it on every build, but it would be a bit slow for your typical development cycle:
<profiles>
<profile>
<id>docs</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>pdf</id>
<phase>site</phase>
<goals>
<goal>pdf</goal>
</goals>
<configuration>
<outputDirectory>
${project.reporting.outputDirectory}
</outputDirectory>
<aggregate>false</aggregate>
</configuration>
</execution>
</executions>
</plugin>
</profile>
</profiles>
You can activate the profile on the command line with -P docs or use an activation configuration if you want to be finer-grained.

Related

Intellij path rule to automatically recognize generated sources folder

I would like to know if it is possible to set up a rule that marks a generated sources folder as generated sources root in Intellij Idea automatically.
Usually, Intellij detects the target/generated-sources directory as generated sources. My problem is that I also need it to automatically recognize the directory target/generated as generated sources, which Intellij never did in my case.
This is because of a maven plugin that I use for generating code from XSD schema:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf.version}</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<xsdOptions>
<xsdOption>
<xsd>src/main/resources/schema.xsd</xsd>
<packagename>org.example.project.common.request</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For some reason, this plugin generates code into the target/generated directory, and not into the target/generates-sources, of which I read that it is the convention and the default from many points of view.
I've tried searching on the web with similar keywords like in the title, but this was the closest solution to what I wanted to achieve. And even this solution doesn't solve my problem because Intellij doesn't allow setting some path patterns; it only offers a few options that don't include target/generated directory.
Another solution suggests changing the target output, which I can't do in every single project I work on; that is not a solution either.
This is important to me because I work with many projects, and sometimes when my code builds with maven but doesn't compile with Intellij I forget to check whether I marked all the generated folders as sources, or I don't even know there are generated sources in the project.
Does someone know a way I can achieve that Intellij automatically detects source files in target/generated directory?

jaxws-maven-plugin to create stubs and include wsdls in target location

During the development, I am facing some issues to generate stubs with maven jaxws-maven-plugin. My requirment is given below.
I have some wsdls in my specified location, now my jaxws-maven-plugin will read them from the specified location and will create the stubs files for me. In the In the stubs files wsdlLocation will be the name of the wsdl files exist on the each location and I will specify the location manually.
Secondly, maven will also copy the wsdl files in the location where classes are build. So, latter I can refer to those wsdls locally.
I have written my plugin where I am able to generate the stub classes but wsdl file locations not containing the location I want. Also need help to copy the wsdl files to the location I need.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${project.build.directory}/wsdl/coh/BCS_COH-CXP9022427-${coh.version}/wsdl</wsdlDirectory>
<wsdlfiles>
<wsdlfile>\Service.wsdl</wsdlfile>
</wsdlfiles>
<wsdlLocation>/*</wsdlLocation>
<sourceDestDir>src/main/java</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
After several googling, I found the answer. Firstly I was using org.codehaus.mojo's jaxws-maven-plugin but above code will work if one use
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2.1</version>

maven-eclipse-plugin and encoding file

How do we force the Eclipse project to use a specific encoding format for a specific type of file ?
Example : UTF-8 for *.sql and ISO-8859-1 for *.java
I can do that in Eclipse of course.
But for the benefit of the team and any new comer, i would like to automatize this task in the build process.
Thankls in advance.
Assuming your sql files are located in a folder identified as a resource (eg /src/main/resources), you can specify a different encoding using the maven-resource plugin.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
...
</build>
And source encoding is specified by the system or manually by something like:
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
For others that don't know how to do this in Eclipse:
Window >> Preferences >> General >> Content Types
Select appropriate content type.
Specify specific encoding for that content type at bottom of window.

How to display dependency conflicts in 'mvn site'

I can easily see if there are conflicts between (transitive) dependency versions using:
mvn dependency:tree -Dverbose=true
... this will show the full resolution tree, including which elements were omitted (for duplicate or conflict or whatever). What I would like to do is to add the full tree to the 'mvn site' report.
Currently, the site report includes the dependency tree but only as resolved, i.e., without any conflicts. I see in the project-info-reports plugin that there is not currently any way to do what I want using the standard report.
I tried adding a section to the pom to include the maven-dependency-plugin 'tree' goal with the outputFile specified, but it wasn't included when I ran 'mvn site'. It was something like this:
<reporting>
....
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<reportSets>
<reportSet>
<id>deptree</id>
<reports>
<report>tree</report>
</reports>
<configuration>
<verbose>true</verbose>
<outputFile>${project.reporting.outputDirectory}/deptree.txt</outputFile>
</configuration>
Of course, the 'tree' goal is explicitly identified as not a report, but I was hoping to at least be able to produce a file that I could link to from the generated site. No dice.
Is there any way to force an arbitrary plugin's goal to execute during site generation? Am I totally out of luck here? Obviously I could write my own reporting plugin to do this, and/or submit a patch for the project-info-reports plugin, but I want to make sure I've exhausted all the built-in maven options.
(I'm using maven 2.1.0, but I didn't see anything about a change to this functionality in the release notes for later versions.)
Is there any way to force an arbitrary plugin's goal to execute during site generation? Am I totally out of luck here?
Just to answer your question, you can bind a mojo to the pre-site phase of the Site Lifecycle:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>tree</id>
<phase>pre-site</phase>
<goals>
<goal>tree</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
...
</reporting>
If you then run mvn site, dependency:tree will run.

How to generate JUnit sources using maven-gunit-plugin

I have maven configured to run gunit (an ANTLR grammar unit testing tool) through the maven-gunit-plugin. gunit, however, has two different modes. The first mode causes gunit to act as an interpreter, reading through the *.gunit (or *.testsuite) file, interpreting it, and displaying the results. It can be configured as such:
<plugin>
<groupId>org.antlr</groupId>
<artifactId>maven-gunit-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<id>maven-gunit-plugin</id>
<phase>test</phase>
<goals>
<goal>gunit</goal>
</goals>
</execution>
</executions>
</plugin>
The second mode causes gunit to generate source code that can be run by JUnit. How can I instruct the maven-gunit-plugin to generate JUnit sources instead of acting as an interpreter?
A few notes:
I can change the test phase to "generate-test-sources" to cause the maven plugin to run at the correct time.
I couldn't find any useful documentation on the maven-gunit-plugin
I've seen people use exec-maven-plugin to run gunit with a specific command line option, but I'm not looking to do that.
EDIT / RESOLUTION:
After reading the various responses, I downloaded the ANTLR source code, which includes the maven-gunit-plugin. The plugin does not support junit generation. It turns out that the codehaus snapshot of the gunit-maven-plugin and the exec plugin are currently the only options.
I found a discussion through MNG-4039 that is illustrated with a maven-gunit-plugin gunit-maven-plugin sample. I'll let you read the whole article but, according to the author, you should end up with something like this:
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.1.1</version>
</dependency>
<!-- Here is the 'extra' dep -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.1.1</version>
<!-- we try to use scope to hide it from transitivity -->
<scope>test</scope> <!-- or perhaps 'provided' (see later discussion) or 'import' (maven >= 2.0.9) -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gunit-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I didn't test this configuration myself and can't thus confirm everything is working out of the box. I don't even know if the plugin has been released in a non SNAPSHOT version. The only thing I can confirm is that it seems indeed very hard to find "real" documentation about the maven-gunit-plugin.
There is sad news here
I found out so far there is no
GUnit-functionality (be it JUnit
Test-Generation or direct invocation
of GUnit) for maven right now. I
already mailed with Jim Idle concering
the state of GUnit in the
antlr3-maven-plugin and learned that
there is a patch to the old version of
the maven-plugin waiting in the queue.
I think this workaround that is the only option.