Search code examples
mavenjavadocmaven-javadoc-plugin

maven-javadoc-plugin does not generate javadocs


I have a project with the following structure:

parent
 |-api
 |-plugin (depends on api)

The project is build using the clean install package tasks from maven on the parent module. The JARs generate correctly but the javadocs don't. How can I fix this?

This is what my parent module's pom looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>PluginLogger</groupId>
    <artifactId>parent</artifactId>
    <version>1.1</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <modules>
        <module>plugin</module>
        <module>api</module>
    </modules>

    // repositories and dependencies go here...

    <build>
        <defaultGoal>clean install package</defaultGoal>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.6.3</version>
                    <configuration>
                        <outputDirectory>${project.build.directory}/javadoc</outputDirectory>
                        <sourceFileIncludes>
                            <include>**/me/suprB/pluginlogger/api/**/*.java</include>
                        </sourceFileIncludes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <phase>package</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

I just want to generate the Javadocs for the "api" module, not the "plugin" one.


Solution

  • I created a small POC with a similar structure you provided. Based on my findings I would like to suggest the following:

    • Please do not use the trailing ** in the <include> tag
    • use reportOutputDirectory and destDir configurations instead of outputDirectory
    • In my opinion you should not use pluginManagement here, since the plugin is used only by the parent pom.

    Sample Parent POM

    This is the actual pom.xml for my PoC's parent module:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.github.tcsizmadia</groupId>
        <artifactId>maven-javadoc-sandbox</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <modules>
            <module>api</module>
            <module>plugin</module>
        </modules>
    
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.6.3</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <phase>package</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                            <configuration>
                                <sourceFileIncludes>
                                    <sourceFileInclude>com/github/tcsizmadia/api/**</sourceFileInclude>
                                </sourceFileIncludes>
                                <reportOutputDirectory>${project.build.directory}</reportOutputDirectory>
                                <destDir>javadoc</destDir>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    Directory tree after issuing mvn clean install on parent module:

    ├── javadoc
    │   ├── com
    │   │   └── github
    │   │       └── tcsizmadia
    │   │           └── api
    │   │               └── class-use
    │   ├── legal
    │   ├── resources
    │   └── script-dir
    │       └── images
    └── javadoc-bundle-options
    

    As you can see, it does not contain any documentation from plugin module - just from the api, as you requested.