Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Overview

The Apache Maven Javadoc plugin allows us to generate Javadocs for the specified project during the Maven build. Furthermore, the plugin is pretty convenient since it generates the Javadocs automatically using the standard javadoc tool.

In this quick tutorial, we’ll take a look at how to disable the Javadoc generation in Maven builds temporarily.

2. Introduction to the Problem

We can configure the Maven Javadoc plugin in our pom.xml to generate Javadocs and attach them to the built jar files, for example:

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
...

This is convenient. However, sometimes, when we do a release, we don’t want to attach the Javadocs to the jar file. But, we don’t want to remove the Maven Javadoc plugin, either.

Therefore, we need a way to skip the Javadoc generation in a build. Next, let’s see how to achieve it.

3. The maven.javadoc.skip Option

The Maven Javadoc plugin has provided a maven.javadoc.skip option to skip the Javadoc generation.

Our Maven build won’t generate Javadocs if we pass this option with the value true when we build our project:

mvn clean install -Dmaven.javadoc.skip=true

4. Skip Javadoc Generation With the Maven Release Plugin

The Maven Release Plugin is widely used for automatic release management.

Let’s say we’ve configured both the Maven Release plugin and the Javadoc plugin in our project.

Now, we’d like to ask the Maven Javadoc plugin to generate Javadocs for regular builds but skip the Javadoc generation only for the release builds.

There are two approaches we can use to achieve this goal.

The first way to go is to pass an argument to the mvn command line when we start a release build:

mvn release:perform -Darguments="-Dmaven.javadoc.skip=true"

Alternatively, we can add the maven.javadoc.skip=true argument in our Maven Release plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <configuration>
        <arguments>-Dmaven.javadoc.skip=true</arguments>
    </configuration>
</plugin>

In this way, all builds with the Maven Release plugin will skip the Javadoc generation.

5. Conclusion

In this quick article, we’ve addressed how to skip Javadoc generation when the Maven Javadoc plugin is configured in our pom.xml.

Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – Maven (eBook) (cat=Maven)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.