The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

Cleaning a Maven project using the command-line

The Clean Plugin can be called to execute in the command-line without any additional configurations. Like the other plugins, to run the Clean Plugin, you use:

  mvn clean:clean

where the first clean refers to the plugin's alias, and the second clean refers to the plugin goal.

However, the Clean Plugin is a special plugin and is bound to its own special lifecycyle phase called clean. Thus, for simplicity, it can also be executed by using:

  mvn clean

or with other phases/goals like:

  mvn clean package site

Running the Clean Plugin automatically during a build

If for some reason, adding clean to the command-line is not option, the Clean Plugin can be put into a project's pom.xml so that it gets executed everytime the project is built. Below is a sample pom.xml for running the Clean Plugin in the initialize phase everytime the project is built: