0

I have a multi-module project. In the parent pom (which is not the aggregator POM), I'm using maven-javadoc-plugin. It has two executions, both in the package phase, one for the jar goal, and one for the aggregate-jar goal.

This nicely generates a full aggregate Javadoc jar of all the (non-test) classes in the build.

What I need to be able to do is generate TWO Javadoc jars, one exactly as it's generating now, but another that covers a limited set of modules, and possibly excludes particular packages or classes.

I thought perhaps that this would require adding TWO "execution" elements, both for the "aggregate-jar" task, but with different configuration values. This didn't appear to do anything. It just generated a single Javadoc tree, for "all" the classes. How do I get this done?

This was my attempt to make this happen:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.4</version>
            <configuration>
                <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
            <executions>
                <execution>
                    <id>module-javadoc-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <show>protected</show>
                        <detectLinks>true</detectLinks>
                    </configuration>
                </execution>
                <execution>
                    <id>aggregated-documentation-all</id>
                    <phase>package</phase>
                    <inherited>false</inherited>
                    <goals>
                        <goal>aggregate-jar</goal>
                    </goals>
                    <configuration>
                       <sourcepath>
                        ../something-api:
                        ../something-impl:
                        ../something-else-api:
                        ../something-else-impl:
                       </sourcepath>
                       <destDir>all</destDir>
                       <finalName>all</finalName>
                       <show>protected</show>
                       <detectLinks>true</detectLinks>
                    </configuration>
                </execution>
                <execution>
                    <id>aggregated-documentation-interface</id>
                    <phase>package</phase>
                    <inherited>false</inherited>
                    <goals>
                        <goal>aggregate-jar</goal>
                    </goals>
                    <configuration>
                       <sourcepath>
                        ../something-api:
                        ../something-else-api:
                       </sourcepath>
                       <destDir>interface</destDir>
                       <finalName>interface</finalName>
                       <show>protected</show>
                       <detectLinks>true</detectLinks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Naman
  • 27,789
  • 26
  • 218
  • 353
David M. Karr
  • 14,317
  • 20
  • 94
  • 199

1 Answers1

0

Probably you are missing an important part there in the <configuration> and i.e <classifier>

What is the purpose of Classifier tag in maven?

So your execution phases shall work just fine

<configuration>
    <classifier>aggregated-documentation-all</classifier>
    ....
</configuration>
...
...
<configuration>
    <classifier>aggregated-documentation-interface</classifier>
    ....
</configuration>

Source - Ant to Maven - multiple build targets answer from @Tim O'Brien

Useful Insights - Maven JAR plugin

Disclaimer - Why-you-shouldnt?

Edit1 - Noticed further from comments that your pom is an aggregator pom.xml in which case would suggest you use -

<inherited>true</inherited>

and also keep a point of specifying different <destDir> for different executions to confirm looking at the different outputs.


Edit2 - To clarify more using an example. What worked for me here was editing the parent modules pom.xml to include the below stated. Executing mvn clean install generates two different /target folder for this change using different configuration specified in the executions -

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.4</version>
            <configuration>
                <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
            <executions>
                <execution>
                    <!--This shall generate the package inside the /target folder of parent module-->
                    <id>first</id>
                    <phase>package</phase>
                    <inherited>true</inherited>
                    <goals>
                        <goal>aggregate-jar</goal>
                    </goals>
                    <configuration>
                        <classifier>first</classifier>
                        <show>protected</show>
                        <detectLinks>true</detectLinks>
                    </configuration>
                </execution>
                <execution>
                    <!--This shall generate the /target on project.basedir of your project-->
                    <id>second</id>
                    <phase>package</phase>
                    <inherited>true</inherited>
                    <goals>
                        <goal>aggregate-jar</goal>
                    </goals>
                    <configuration>
                        <destDir>${project.basedir}</destDir>
                        <classifier>second</classifier>
                        <!--Notice the package in this /target would not include following packages-->
                        <excludePackageNames>com.xyz.in.my.project</excludePackageNames>
                        <finalName>second</finalName>
                        <show>protected</show>
                        <detectLinks>true</detectLinks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • Thanks for replying, but this seemed to make no difference at all. Note that my top-level pom is an aggregate pom. I defined the javadoc plugin in the parent pom, which is one of the child modules. All the other child modules specify that as its parent pom. I ran "mvn install" at the top level, and it produced the "target/*-javadoc.jar", which appears to have the javadoc for all the classes. I see no indication in any output of any affect from the classifier settings. – David M. Karr Dec 03 '16 at 03:06
  • @David okay, the question read *parent pom(which is not the aggregator POM)*. Also note if you are using it as aggregator POM you probably want to specify `true` – Naman Dec 03 '16 at 10:38
  • I'm really getting confused by what you're saying here. I was pretty clear in the original posting that I have an aggregator pom AND a parent pom, and my javadoc plugin setting is in the parent pom. The POM in the top directory is the aggregator pom, and one of the child poms is the parent pom. – David M. Karr Dec 03 '16 at 17:23
  • @DavidM.Karr I've update the answer with an example what works for me on a multimodule hierarchical project. – Naman Dec 03 '16 at 19:43
  • This is still not working. I'm going to try a different tack on this, and the following shows my current issue with this idea: http://stackoverflow.com/questions/41002637/having-trouble-generating-aggregate-javadoc-in-maven-child-module . – David M. Karr Dec 06 '16 at 20:26