Apache

Docs Plugins

Clean Plugin 3.5.0 · Other versions

The Maven Clean Plugin is a plugin that removes files generated at build-time in a project's directory.

Source
Edit this page
Wrong?
Report a problem

Delete Additional Files Not Exposed to Maven

The Maven Clean Plugin will delete the target directory by default. You may configure it to delete additional directories and files. The following example shows how:

<build>
  [...]
  <plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>3.5.0</version>
    <configuration>
      <filesets>
        <fileset>
          <directory>some/relative/path</directory>
          <includes>
            <include>**/*.tmp</include>
            <include>**/*.log</include>
          </includes>
          <excludes>
            <exclude>**/important.log</exclude>
            <exclude>**/another-important.log</exclude>
          </excludes>
          <followSymlinks>false</followSymlinks>
        </fileset>
      </filesets>
    </configuration>
  </plugin>
  [...]
</build>

Note: The directory in the fileset is a relative path inside a project, in other words,

  <directory>some/relative/path</directory>

is equivalent to:

  <directory>/home/dashorst/workspaces/maven-site/target/plugin-demo/src/maven-clean-plugin/some/relative/path</directory>

You could also define file set rules in a parent POM. In this case, the clean plugin adds the subproject basedir to the defined relative path.

Note: The fast delete method will not work for any fileset which defines any includes or excludes, or sets followSymlinks to false, or sets useDefaultExcludes to true.