The Maven Clean Plugin – Maven清洁插件

最后修改: 2018年 4月 19日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

This quick tutorial describes the clean plugin, one of the core plugins of the Maven build tool.

本快速教程介绍了clean插件,这是Maven构建工具的核心插件之一。

For an overview of the other core plugins, refer to this article.

关于其他核心插件的概述,请参考这篇文章

2. Plugin Goal

2.插件目标

The clean lifecycle has only one phase named clean that is automatically bound to the only goal of the plugin with the same name. This goal can, therefore, be executed with the command mvn clean.

clean生命周期只有一个名为clean的阶段,它被自动绑定到插件中唯一的同名目标上。因此,这个目标可以用mvn clean命令执行。

The clean plugin is already included in the super POM, thus we can use it without specifying anything in the project’s POM.

clean插件已经包含在超级POM中,因此我们可以使用它,而无需在项目的POM中指定任何东西。

This plugin, as its name implies, cleans the files and directories generated during the previous build. By default, the plugin removes the target directory.

这个插件,正如它的名字所暗示的,清理了在前一次构建过程中产生的文件和目录。默认情况下,该插件会删除target目录。

3. Configuration

3.配置

We can add directories to be cleaned using the filesets parameter:

我们可以使用filesets参数添加要清理的目录。

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>output-resources</directory>
            </fileset>
        </filesets>
    </configuration>
</plugin>

The latest version of this plugin is listed here.

该插件的最新版本列在这里

If the output-resources directory contains some generated resources, it cannot be removed with the default settings. The change we’ve just made instructs the clean plugin to delete that directory in addition to the default one.

如果output-resources目录包含一些生成的资源,在默认设置下,它不能被删除。我们刚才的改变指示clean插件除了删除默认目录外,还要删除该目录。

4. Conclusion 

4.结论

In this article, we went over the clean plugin and instructed how to customize it.

在这篇文章中,我们介绍了clean插件,并指导了如何定制它。

The complete source code for this tutorial can be found over on GitHub.

本教程的完整源代码可以在GitHub上找到over

Next »

The Maven Verifier Plugin

« Previous

The Maven Deploy Plugin