3

I would like use Maven for creating site for my application. This is a multi-module app, the parent module is simple site module, and first child is a core of app, the second is a GUI (Swing).

I now use follow for parent pom.xml

<modules>
    <module>core</module>
    <module>kayako-desktop</module>
</modules>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-site-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <locales>en</locales>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <aggregate>true</aggregate>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-changes-plugin</artifactId>
            <version>2.4</version>
        </plugin>
    </plugins>
</reporting>

My core's pom:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                        <goal>javadoc</goal>
                    </goals>
                </execution>

            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <links>
                    <link>http://download.oracle.com/javase/6/docs/api/</link>
                </links>    
            </configuration>
        </plugin>    
    </plugins>

</reporting>

(I stripped out unrelated parts from both)

The problem: I tried mvn site:stage, but javadoc is not collected from core module. What do I wrong?

Jean-Rémy Revy
  • 5,431
  • 3
  • 36
  • 64
Gabor Garami
  • 1,135
  • 7
  • 25
  • See this related question: http://stackoverflow.com/questions/3404322/how-to-use-javadocaggregate-properly-in-multi-module-maven-project – Mark Butler Mar 19 '13 at 05:23

1 Answers1

3

Configure the javadoc plugin in the <reportPlugins> section of the configuration for the maven-site-plugin, in the parent pom.

Here's what worked for me.

In the parent pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9</version>
                        <reportSets>
                            <reportSet>
                                <id>aggregate</id>
                                <reports>
                                    <report>aggregate</report>
                                </reports>
                            </reportSet>
                        </reportSets>
                        <configuration>
                        <!-- Here you can add special configurations for your javadoc, if needed -->
                        </configuration>
                    </plugin>
                    <!-- Here you can also configure more report plugins -->
                    <!-- for your site, such as maven-project-info-reports-plugin -->
                </reportPlugins>
            </configuration>
        </plugin>
    <!-- ... -->
    </plugins>
</build>
<!-- ... -->
<distributionManagement>
    <site>
        <id>website</id>
        <url>http://site.url/can/be/tentative/or/hypothetical</url>
    </site>
</distributionManagement>

In each of the child poms, you can also configure specific reports for the site plugin, for example, surefire test reports or project info. However, you shouldn't need to place any javadoc plugin configurations there (unless you also want non-aggregated javadocs for your child modules).

You should then be able to do mvn site site:stage from the parent directory. To view your aggregated javadocs, point your browser to target/staging/index.html in that directory, and click "Project Reports" and then "JavaDocs" in the index on the left-hand side of the page.

Additional tip:

Sometimes I want to look quickly at the aggregated javadocs without having to do an entire site site:stage, which does more stuff and takes longer. So I also include a configuration for the maven-javadoc-plugin directly in the <plugin> section of the parent pom. That way, I can run mvn javadoc:aggregate and quickly get the aggregated javadocs in target/site/apidocs/index.html.

Andrew
  • 246
  • 2
  • 10
  • Thank you. The mentioned project is not my project anymore, but I'll use your tip in my another project. And I did not know site:stage target before, this is very useful! – Gabor Garami Jul 11 '13 at 12:35