Fork me on GitHub

clean:clean

Full name:

org.apache.maven.plugins:maven-clean-plugin:4.0.0-beta-3:clean

Description:

Goal which cleans the build. This attempts to clean a project's working directory of the files that were generated at build-time. By default, it discovers and deletes the directories configured in project.build.directory, project.build.outputDirectory, project.build.testOutputDirectory, and project.reporting.outputDirectory.

Files outside the default may also be included in the deletion by configuring the filesets tag.


See also: Fileset

Attributes:

  • Requires a Maven project to be executed.
  • The goal is not marked as thread-safe and thus does not support parallel builds.
  • Since version: 2.0.

Optional Parameters

Name Type Since Description
<excludeDefaultDirectories> boolean 2.3 Disables the deletion of the default output directories configured for a project. If set to true, only the files/directories selected via the parameter filesets will be deleted.

Starting with 3.0.0 the property has been renamed from clean.excludeDefaultDirectories to maven.clean.excludeDefaultDirectories.

<failOnError> boolean 2.2 Indicates whether the build will continue even if there are clean errors.

This parameter applies to the non-fast deletion path only. When fast is true (the default), the atomic directory move immediately frees the original path, and any subsequent deletion failures occur in the staging area (fastDir). Those failures cannot affect the new build and are always logged as warnings at session end, regardless of this setting.

<fast> boolean 3.2 Enables fast clean. When set to true, each directory to be deleted is first atomically moved inside the maven.clean.fastDir staging directory, immediately freeing the original path, and the actual file deletion is then performed in the background. If an atomic move is not supported (e.g. cross-device), the plugin falls back to immediate synchronous deletion transparently.

This is the default mode as of 4.0.0: the atomic move is essentially free, so even small projects benefit from the freed directory being available immediately. When failOnError is true (the default), the actual deletion runs synchronously so that errors can still fail the build; when failOnError is false, deletion proceeds in the background and any failure there does not affect build correctness.

Note: failOnError has no effect when fast clean is enabled. Once the atomic move succeeds, the original path is freed and any subsequent failures occur in the staging area only — they cannot affect build correctness. Errors are therefore always logged as warnings at session end. Use fast=false if you need the build to fail on clean errors.

<fastDir> Path 3.2 When fast clean is enabled, the location where directories to be deleted will be moved prior to background deletion. If not specified, the ${rootDirectory/.mvn/target/clean} directory will be used. The .mvn/target/ tree is covered by the standard target/ gitignore pattern, and used for Maven infrastructure such as the project-local repository. Because it is outside of any subproject target/ tree, it is never accidentally deleted by a concurrent or subsequent clean invocation. If the ${build.directory} is on a different filesystem from the project root, you will have to adjust this property explicitly. In order for fast clean to work correctly, this directory and the various directories that will be deleted should usually reside on the same volume. The exact conditions are system-dependent though, but if an atomic move is not supported, the immediate deletion mechanism will be used.
See also: fast
<fastMode> String 3.2 Mode to use when using fast clean. Values are: background to start deletion immediately and waiting for all files to be deleted when the session ends, at-end to indicate that the actual deletion should be performed synchronously when the session ends, or defer to specify that the actual file deletion should be started in the background when the session ends. This should only be used when maven is embedded in a long-running process.
See also: fast
<filesets> Fileset[] 2.1 The list of file sets to delete, in addition to the default directories. For example:
<filesets>
  <fileset>
    <directory>src/main/generated</directory>
    <followSymlinks>false</followSymlinks>
    <useDefaultExcludes>true</useDefaultExcludes>
    <includes>
      <include>*.java</include>
    </includes>
    <excludes>
      <exclude>Template*</exclude>
    </excludes>
  </fileset>
</filesets>
<followSymLinks> boolean 2.1 Sets whether the plugin should follow symbolic links while deleting files from the default output directories of the project.

Starting with 3.0.0 the property has been renamed from clean.followSymLinks to maven.clean.followSymLinks.

<force> boolean 3.4.2 Whether to force the deletion of read-only files.
<retryOnError> boolean 2.4.2 Indicates whether the plugin should undertake additional attempts (after a short delay) to delete a file if the first attempt failed. This is meant to help deleting files that are temporarily locked by third-party tools like virus scanners or search indexing.
<skip> boolean 2.2 Disables the plugin execution.

Starting with 3.0.0 the property has been renamed from clean.skip to maven.clean.skip.

<verbose> Boolean 2.1 Sets whether the plugin runs in verbose mode. As of plugin version 2.3, the default value is derived from Maven's global debug flag (compare command line switch -X).

Starting with 3.0.0 the property has been renamed from clean.verbose to maven.clean.verbose.

Parameter Details

<excludeDefaultDirectories>

Disables the deletion of the default output directories configured for a project. If set to true, only the files/directories selected via the parameter filesets will be deleted.

Starting with 3.0.0 the property has been renamed from clean.excludeDefaultDirectories to maven.clean.excludeDefaultDirectories.

  • Type: boolean
  • Since: 2.3
  • Required: No

<failOnError>

Indicates whether the build will continue even if there are clean errors.

This parameter applies to the non-fast deletion path only. When fast is true (the default), the atomic directory move immediately frees the original path, and any subsequent deletion failures occur in the staging area (fastDir). Those failures cannot affect the new build and are always logged as warnings at session end, regardless of this setting.

  • Type: boolean
  • Since: 2.2
  • Required: No

<fast>

Enables fast clean. When set to true, each directory to be deleted is first atomically moved inside the maven.clean.fastDir staging directory, immediately freeing the original path, and the actual file deletion is then performed in the background. If an atomic move is not supported (e.g. cross-device), the plugin falls back to immediate synchronous deletion transparently.

This is the default mode as of 4.0.0: the atomic move is essentially free, so even small projects benefit from the freed directory being available immediately. When failOnError is true (the default), the actual deletion runs synchronously so that errors can still fail the build; when failOnError is false, deletion proceeds in the background and any failure there does not affect build correctness.

Note: failOnError has no effect when fast clean is enabled. Once the atomic move succeeds, the original path is freed and any subsequent failures occur in the staging area only — they cannot affect build correctness. Errors are therefore always logged as warnings at session end. Use fast=false if you need the build to fail on clean errors.

  • Type: boolean
  • Since: 3.2
  • Required: No

<fastDir>

When fast clean is enabled, the location where directories to be deleted will be moved prior to background deletion. If not specified, the ${rootDirectory/.mvn/target/clean} directory will be used. The .mvn/target/ tree is covered by the standard target/ gitignore pattern, and used for Maven infrastructure such as the project-local repository. Because it is outside of any subproject target/ tree, it is never accidentally deleted by a concurrent or subsequent clean invocation. If the ${build.directory} is on a different filesystem from the project root, you will have to adjust this property explicitly. In order for fast clean to work correctly, this directory and the various directories that will be deleted should usually reside on the same volume. The exact conditions are system-dependent though, but if an atomic move is not supported, the immediate deletion mechanism will be used.
See also: fast
  • Type: java.nio.file.Path
  • Since: 3.2
  • Required: No

<fastMode>

Mode to use when using fast clean. Values are: background to start deletion immediately and waiting for all files to be deleted when the session ends, at-end to indicate that the actual deletion should be performed synchronously when the session ends, or defer to specify that the actual file deletion should be started in the background when the session ends. This should only be used when maven is embedded in a long-running process.
See also: fast
  • Type: java.lang.String
  • Since: 3.2
  • Required: No

<filesets>

The list of file sets to delete, in addition to the default directories. For example:
<filesets>
  <fileset>
    <directory>src/main/generated</directory>
    <followSymlinks>false</followSymlinks>
    <useDefaultExcludes>true</useDefaultExcludes>
    <includes>
      <include>*.java</include>
    </includes>
    <excludes>
      <exclude>Template*</exclude>
    </excludes>
  </fileset>
</filesets>

<followSymLinks>

Sets whether the plugin should follow symbolic links while deleting files from the default output directories of the project.

Starting with 3.0.0 the property has been renamed from clean.followSymLinks to maven.clean.followSymLinks.

  • Type: boolean
  • Since: 2.1
  • Required: No

<force>

Whether to force the deletion of read-only files.
  • Type: boolean
  • Since: 3.4.2
  • Required: No

<retryOnError>

Indicates whether the plugin should undertake additional attempts (after a short delay) to delete a file if the first attempt failed. This is meant to help deleting files that are temporarily locked by third-party tools like virus scanners or search indexing.
  • Type: boolean
  • Since: 2.4.2
  • Required: No

<skip>

Disables the plugin execution.

Starting with 3.0.0 the property has been renamed from clean.skip to maven.clean.skip.

  • Type: boolean
  • Since: 2.2
  • Required: No

<verbose>

Sets whether the plugin runs in verbose mode. As of plugin version 2.3, the default value is derived from Maven's global debug flag (compare command line switch -X).

Starting with 3.0.0 the property has been renamed from clean.verbose to maven.clean.verbose.

  • Type: java.lang.Boolean
  • Since: 2.1
  • Required: No