0

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.

3
  • What's the POM of each module? Does it contain the javadoc plugin config? Commented Jan 2, 2024 at 19:48
  • 1
    I'm not sure the underlying javadoc utility allows for wildcards at the beginning of package names. Can you try with only a wildcard at the end of the package name? You can use something like project.basedir at the beginning to deal with project locations ${project.basedir}/src/main/java/com/acme/foo Commented Jan 2, 2024 at 19:48
  • @GaëlJ I did not configure the javadoc in any other POM. What should I put? Do you have an example? Commented Jan 2, 2024 at 20:38

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I wish you good luck on your journey as a Java developer! At the first sight, Maven plugins (and Maven et al.) seems a bit complicated, but the documentation is fine and you'll see how flexible is it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.