lambgrp425
lambgrp425

Reputation: 706

Using Maven to create Javadocs as a zip file instead of a jar file

I am trying to figure out how to create a zip file of my Javadocs instead of a jar file using Maven. I am currently creating a jar file using the maven-javadoc-plugin.

 <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-javadoc-plugin</artifactId>
     <version>2.7</version>
     <executions>
         <execution>
             <id>attach-javadoc</id>
             <goals>
                 <goal>jar</goal>
             </goals>
         </execution>
    </executions>
</plugin>

I looked at the goals listed here but found nothing helpful to this end. Is this possible using maven-javadoc-plugin or must some other plugin be used?

Upvotes: 2

Views: 2241

Answers (1)

Mithun
Mithun

Reputation: 8077

You need to use maven-javadoc-plugin in combination with maven-assembly-plugin to package the generated docs in a zip. First, only generate the apidocs using javadoc:javadoc goal, but don't package it. This generates the docs in ${project.build.directory}/apidocs by default.

Then, use maven-assembly-plugin to package these docs as follows:

Add maven assembly plugin:

<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>

Now, configure maven assembly plugin:

<?xml version="1.0" encoding="UTF-8"?>
<assembly>
  <id>${project.build.finalName}</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/apidocs</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

Upvotes: 4

Related Questions