1. Overview

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

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

2. Plugin Goal

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.

The clean plugin is already included in the super POM, thus we can use it without specifying anything in the project’s 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.

3. Configuration

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

<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.

4. Conclusion

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

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


« 上一篇: Maven Site 插件