1. Overview
1.概述
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.
Apache Maven Javadoc插件允许我们在Maven构建期间为指定项目生成Javadoc。此外,该插件使用标准javadoc工具自动生成Javadoc,因此相当方便。
In this quick tutorial, we’ll take a look at how to disable the Javadoc generation in Maven builds temporarily.
在这个快速教程中,我们将看看如何在Maven构建中暂时禁用Javadoc的生成。
2. Introduction to the Problem
2.对问题的介绍
We can configure the Maven Javadoc plugin in our pom.xml to generate Javadocs and attach them to the built jar files, for example:
我们可以在pom.xml中配置Maven Javadoc插件,以生成Javadocs,并将其附在已建的jar文件中,例如。
...
<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.
这很方便。然而,有时我们在发布时,不想把Javadocs附在jar文件中。但是,我们也不想删除Maven Javadoc插件。
Therefore, we need a way to skip the Javadoc generation in a build. Next, let’s see how to achieve it.
因此,我们需要一种方法来跳过构建中的Javadoc生成。接下来,让我们看看如何实现它。
3. The maven.javadoc.skip Option
3.maven.javadoc.skip选项
The Maven Javadoc plugin has provided a maven.javadoc.skip option to skip the Javadoc generation.
Maven Javadoc插件提供了一个maven.javadoc.skip选项来跳过Javadoc的生成。
Our Maven build won’t generate Javadocs if we pass this option with the value true when we build our project:
如果我们在构建项目时传递该选项的值为true,那么我们的Maven构建就不会生成Javadocs。
mvn clean install -Dmaven.javadoc.skip=true
4. Skip Javadoc Generation With the Maven Release Plugin
4.利用Maven发布插件跳过Javadoc的生成
The Maven Release Plugin is widely used for automatic release management.
Maven Release Plugin被广泛用于自动发布管理。
Let’s say we’ve configured both the Maven Release plugin and the Javadoc plugin in our project.
假设我们在项目中同时配置了Maven Release插件和Javadoc插件。
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.
现在,我们想让Maven Javadoc插件为常规构建生成Javadoc,但只为发布构建跳过Javadoc的生成。
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命令行传递一个参数。
mvn release:perform -Darguments="-Dmaven.javadoc.skip=true"
Alternatively, we can add the maven.javadoc.skip=true argument in our Maven Release plugin configuration:
另外,我们可以在Maven Release插件配置中添加maven.javadoc.skip=true参数。
<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.
这样一来,所有使用Maven Release插件的构建都会跳过Javadoc的生成。
5. Conclusion
5.总结
In this quick article, we’ve addressed how to skip Javadoc generation when the Maven Javadoc plugin is configured in our pom.xml.
在这篇文章中,我们讨论了在pom.xml中配置了Maven Javadoc插件后如何跳过Javadoc的生成。