简体   繁体   中英

How to make maven-javadoc-plugin generate multiple jars?

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>

Probably you are missing an important part there in the <configuration> and ie <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM