开发者

Maven multi-module project site with javadocs

开发者 https://www.devze.com 2023-03-04 07:33 出处:网络
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 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 unr开发者_如何学Pythonelated parts from both)

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号