Maven 3: Generate Javadoc for defined artifacts -
i want generate javadocs artifacts of project within dedicated docs-project.
that means have independent project called "docs" example. in docs/pom.xml define artifacts should included in generated javadocs.
so far learned have generate seperate sources.jar projects want include. there on can't figure out how go one.
for can imagine 2 approaches:
get artifacts (sources.jar) want include, unpack them , somehow point javadoc plugin source directory.
define artifacts interested dependecy , use "dependencysourceinclude" option of javadoc-plugin. not sure if usage intended.
any suggestions how solve problem?
i have found solution self. bit of hack work me. chose go first idea:
get artifacts (sources.jar) want include, unpack them , somehow point javadoc plugin source directory.
this solution has 4 differents parts i'll explain in more detail later:
- generate sources.jars in artifacts want include
- unpack sources.jars
- generate javadoc pointing javadoc-plugin unpacked sources
- package generated apidocs in zip file
now in more detail:
1. generate sources.jars in artifacts want include
to generate sources.jars have use maven-sources-plugin follows:
<build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-source-plugin</artifactid> <version>2.1.2</version> <executions> <execution> <id>bundle-sources</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
you have in every project/module/artifact want include in apidocs.
2. unpack sources.jars
in pom.xml use generate javadocs have add following plugins unpack sources.jar files.
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <executions> <execution> <id>unpack-artifact-sources</id> <phase>generate-resources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactitems> <artifactitem> <groupid>${project.groupid}</groupid> <artifactid><!-- artifact here --></artifactid> <version>${project.version}</version> <classifier>sources</classifier> <overwrite>true</overwrite> </artifactitem> </artifactitems> <outputdirectory>${project.build.directory}/unpack_sources</outputdirectory> </configuration> </execution> <!-- add more unpack-executions here --> </executions> </plugin>
you can add many unpack-execution-blocks like.
3. generate javadoc pointing javadoc-plugin unpacked sources
now tricky part. letting javadoc-plugin know source files. imported definition <sourcepath>
definition. in section define folder have unpacked sources in step 2.
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-javadoc-plugin</artifactid> <version>2.7</version> <configuration> <sourcepath>${project.build.directory}/unpack_sources</sourcepath> </configuration> <executions> <execution> <goals> <goal>javadoc</goal> </goals> <phase>process-resources</phase> </execution> </executions> </plugin>
when call mvn clean install
@ point end site
folder inside target
folder. in site folder you'll find apidocs. make build shiny , stuff want assemble apidocs zip archive.
4. package generated apidocs in zip file
to assemble docs have use maven-assembly-plugin
, assembly-file. first plugin-defintion inside pom:
<plugin> <artifactid>maven-assembly-plugin</artifactid> <executions> <execution> <id>docs-assembly</id> <phase>package</phase> <configuration> <appendassemblyid>false</appendassemblyid> <descriptors> <descriptor>src/main/assembly/assemble.xml</descriptor> </descriptors> </configuration> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
assemble.xml:
<?xml version="1.0" encoding="utf-8"?> <assembly> <id>${project.build.finalname}</id> <formats> <format>zip</format> </formats> <includebasedirectory>false</includebasedirectory> <filesets> <fileset> <directory>target/site/apidocs</directory> <outputdirectory>/</outputdirectory> </fileset> </filesets> </assembly>
Comments
Post a Comment