How to execute maven plugin _after_ all module builds finish

Specifically I am trying to run maven-javadoc-plugin but whenever I change the version numbers on the parent/aggregator pom and all of the children, the first time I run the build it fails because javadoc runs first and can’t find any of the new version packages from the modules because they haven’t been built yet.

I usually end up having to comment javadoc out for one build and then add it back in once the packages are available in nexus for the new version. However, this likely means that I’ve been building javadoc on one build old source jars all the time.

I’ve read suggestions of putting another module in that depends on the other ones but I don’t think i can get a module to build the javadoc for peer modules. Having it in the parent builds all of the javadoc for all of the modules, I just need it to happen later. Thanks. Here’s my javadoc plugin config.

                    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <inherited>false</inherited>
                    <executions>
                        <execution>
                            <id>generate-javadoc</id>
                            <phase>package</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                            <configuration>
                                <aggregate>true</aggregate>
                                <links>
                                    <link>http://java.sun.com/javase/6/docs/api</link>
                                    <link>http://java.sun.com/javaee/5/docs/api</link>
                                </links>
                                <maxmemory>512</maxmemory>
                                <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                                <docletArtifact>
                                    <groupId>org.umlgraph</groupId>
                                    <artifactId>doclet</artifactId>
                                    <version>5.2</version>
                                </docletArtifact>
                                <additionalparam>
                                    -inferrel -inferdep -outputencoding utf8 -hide
                                    java.* -collpackages
                                    java.util.*
                                    -qualify -postfixpackage
                                    -nodefontsize 9 -nodefontpackagesize 7
                                </additionalparam>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Answer

One way to get around this problem is not to invoke javadoc plugin in the normal maven lifecycle phase; instead run it separately.

To be specific, remove <phase> tag from the above plugin definition.

Run mvn install javadoc:javadoc from parent.

This will build and install all the modules and the parent and then run javadoc on them.

Attribution
Source : Link , Question Author : John Russell , Answer Author : Raghuram

Leave a Comment