mavenjarjavadoc

How include javadoc inside single jar with maven assembly plugin


I have a library that I want to provide javadoc for within a single jar file. I use maven assembly plugin to get a single assembly. I have the following settings in the pom.xml:

   <build>
    ...
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>

                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.4</version>
            <executions>
                <execution>
                    <id>attach-javadoc</id>
                    <phase>compile</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
    ...
   <build>

To get a single jar I run this maven command:

clean compile assembly:single

But don't get the javadoc inside the generated jar. What do I have to do besides this?


Solution

  • The standard way of maven is to create a jar that only consists of your application without the javadoc/sources. If you want to offer javadoc/sources to the user of your library then you should use attach-sources / attach-javadoc as documentend here: attach-source-javadoc-artifacts

    This way you'll get additional files within the maven repository with the names