Search code examples
javamavenjavadocmaven-javadoc-plugin

maven-site-plugin to skip Generating "Test Javadoc" report --- maven-javadoc-plugin


What I am trying to achieve:

Generate project website from maven site plugin, without the javadoc for tests (but with javadoc for the classes)

What did I try:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>4.0.0-M8</version>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <outputDirectory>target/javadoc</outputDirectory>
                    <reportOutputDirectory>target/javadoc</reportOutputDirectory>
                    <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>3.3.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.4.3</version>
            </plugin>
        </plugins>
    </reporting>

mvn clean install site -U javadoc:javadoc

Issue:

reproducible 100%, I am seeing this error:

[INFO] Rendering site for default locale
Downloading from spring-milestones: https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-parent/3.1.0-M2/spring-boot-starter-parent-3.1.0-M2-site.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/3.1.0-M2/spring-boot-starter-parent-3.1.0-M2-site.xml
Downloading from spring-milestones: https://repo.spring.io/milestone/org/springframework/boot/spring-boot-dependencies/3.1.0-M2/spring-boot-dependencies-3.1.0-M2-site.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/3.1.0-M2/spring-boot-dependencies-3.1.0-M2-site.xml
[WARNING] Unable to find a URL to the parent project. The parent menu will NOT be added.
[INFO] Relativizing decoration links with respect to localized project URL: http://example.com/abc
[INFO] Rendering content with org.apache.maven.skins:maven-fluido-skin:jar:2.0.0-M2 skin.
[INFO] Skipped "Javadoc" report (maven-javadoc-plugin:3.5.0:javadoc), file "apidocs/index.html" already exists.
[INFO] Skipped "Javadoc" report (maven-javadoc-plugin:3.5.0:javadoc-no-fork), file "apidocs/index.html" already exists.
[INFO] Skipped "Test Javadoc" report (maven-javadoc-plugin:3.5.0:test-javadoc), file "testapidocs/index.html" already exists.
[INFO] Skipped "Test Javadoc" report (maven-javadoc-plugin:3.5.0:test-javadoc-no-fork), file "testapidocs/index.html" already exists.
[INFO] Skipped "Source Xref" report (maven-jxr-plugin:3.3.0:jxr-no-fork), file "xref/index.html" already exists.
[INFO] Skipped "Test Source Xref" report (maven-jxr-plugin:3.3.0:test-jxr-no-fork), file "xref-test/index.html" already exists.
[INFO] Generating "Javadoc" report       --- maven-javadoc-plugin:3.5.0:aggregate-no-fork
[INFO] No previous run data found, generating javadoc.
[INFO] Generating "Test Javadoc" report  --- maven-javadoc-plugin:3.5.0:test-aggregate-no-fork
[INFO] Configuration changed, re-generating javadoc.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping abc
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  28.498 s
[INFO] Finished at: 2023-04-10T08:45:32+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:4.0.0-M6:site (default-site) on project abc: Error generating maven-javadoc-plugin:3.5.0:test-aggregate-no-fork report:
[ERROR] Exit code: 1
[ERROR] error: No public or protected classes found to document.
[ERROR] 1 error
[ERROR] Command line was: cmd.exe /X /C "xxx\bin\javadoc.exe @options @packages"
[ERROR]

Question:

How to generate a project website with maven site plugin, with the javadoc for the classes, but not the javadoc for the tests?


Solution

  • According to Documentation

    To run the Javadocs reports selectively, you need to include only the Javadocs reports that you prefer.

    You can skip generating Javadoc for the tests by removing it from the config

    
        <reporting>
            <plugins>
               ....
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <configuration>
                        <show>public</show>
                    </configuration>
                    <reportSets>
                        <reportSet>
                            <id>default</id>
                            <reports>
                                <report>javadoc</report>
                                <!-- <report>test-javadoc</report> -->
                            </reports>
                        </reportSet>
                        <reportSet>
                            <id>aggregate</id>
                            <reports>
                                <report>aggregate</report>
                            </reports>
                        </reportSet>
                    </reportSets>
                </plugin>
            </plugins>
            ...
        </reporting>