Class CleanMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.clean.CleanMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="clean", threadSafe=true) public class CleanMojo extends org.apache.maven.plugin.AbstractMojo
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.

Since:
2.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private File
    This is where build results go.
    private boolean
    Disables the deletion of the default output directories configured for a project.
    private boolean
    Indicates whether the build will continue even if there are clean errors.
    private boolean
    Enables fast clean if possible.
    static final String
     
    static final String
     
    static final String
     
    private File
    When fast clean is specified, the fastDir property will be used as the location where directories to be deleted will be moved prior to background deletion.
    private String
    Mode to use when using fast clean.
    private Fileset[]
    The list of file sets to delete, in addition to the default directories.
    private boolean
    Sets whether the plugin should follow symbolic links while deleting files from the default output directories of the project.
    private boolean
    Whether to force the deletion of read-only files.
    private File
    This is where compiled classes go.
    private File
    This is where the site plugin generates its pages.
    private boolean
    Indicates whether the plugin should undertake additional attempts (after a short delay) to delete a file if the first attempt failed.
    private org.apache.maven.execution.MavenSession
     
    private boolean
    Disables the plugin execution.
    private File
    This is where compiled test classes go.
    private Boolean
    Sets whether the plugin runs in verbose mode.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes file-sets in the following project build directory order: (source) directory, output directory, test directory, report directory, and then the additional file-sets.
    private Path[]
    Gets the directories to clean (if any).
    private boolean
    Indicates whether verbose output is enabled.
    private static Path
     

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FAST_MODE_BACKGROUND

      public static final String FAST_MODE_BACKGROUND
      See Also:
    • FAST_MODE_AT_END

      public static final String FAST_MODE_AT_END
      See Also:
    • FAST_MODE_DEFER

      public static final String FAST_MODE_DEFER
      See Also:
    • directory

      @Parameter(defaultValue="${project.build.directory}", readonly=true, required=true) private File directory
      This is where build results go.
    • outputDirectory

      @Parameter(defaultValue="${project.build.outputDirectory}", readonly=true, required=true) private File outputDirectory
      This is where compiled classes go.
    • testOutputDirectory

      @Parameter(defaultValue="${project.build.testOutputDirectory}", readonly=true, required=true) private File testOutputDirectory
      This is where compiled test classes go.
    • reportDirectory

      @Parameter(defaultValue="${project.build.outputDirectory}", readonly=true, required=true) private File reportDirectory
      This is where the site plugin generates its pages.
      Since:
      2.1.1
    • verbose

      @Parameter(property="maven.clean.verbose") private Boolean 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.
      Since:
      2.1
    • filesets

      @Parameter private Fileset[] 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>
       
      Since:
      2.1
    • force

      @Parameter(property="maven.clean.force", defaultValue="false") private boolean force
      Whether to force the deletion of read-only files.
      Since:
      3.5.0
    • skip

      @Parameter(property="maven.clean.skip", defaultValue="false") private boolean skip
      Disables the plugin execution.
      Starting with 3.0.0 the property has been renamed from clean.skip to maven.clean.skip.
      Since:
      2.2
    • failOnError

      @Parameter(property="maven.clean.failOnError", defaultValue="true") private boolean failOnError
      Indicates whether the build will continue even if there are clean errors.
      Since:
      2.2
    • retryOnError

      @Parameter(property="maven.clean.retryOnError", defaultValue="true") private boolean 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.
      Since:
      2.4.2
    • excludeDefaultDirectories

      @Parameter(property="maven.clean.excludeDefaultDirectories", defaultValue="false") private boolean 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.
      Since:
      2.3
    • fast

      @Parameter(property="maven.clean.fast", defaultValue="false") private boolean fast
      Enables fast clean if possible. If set to true, when the plugin is executed, a directory to be deleted will be atomically moved inside the maven.clean.fastDir directory and a thread will be launched to delete the needed files in the background. When the build is completed, maven will wait until all the files have been deleted. If any problem occurs during the atomic move of the directories, the plugin will default to the traditional deletion mechanism.
      Since:
      3.2
    • fastDir

      @Parameter(property="maven.clean.fastDir") private File fastDir
      When fast clean is specified, the fastDir property will be used as the location where directories to be deleted will be moved prior to background deletion. If not specified, the ${maven.multiModuleProjectDirectory}/target/.clean directory will be used. If the ${build.directory} has been modified, you'll 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 standard deletion mechanism will be used.
      Since:
      3.2
      See Also:
    • fastMode

      @Parameter(property="maven.clean.fastMode", defaultValue="background") private String 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.
      Since:
      3.2
      See Also:
    • session

      @Parameter(defaultValue="${session}", readonly=true) private org.apache.maven.execution.MavenSession session
  • Constructor Details

    • CleanMojo

      public CleanMojo()
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Deletes file-sets in the following project build directory order: (source) directory, output directory, test directory, report directory, and then the additional file-sets.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - When a directory failed to get deleted.
      See Also:
      • Mojo.execute()
    • isVerbose

      private boolean isVerbose()
      Indicates whether verbose output is enabled.
      Returns:
      true if verbose output is enabled, false otherwise.
    • getDirectories

      private Path[] getDirectories()
      Gets the directories to clean (if any). The returned array may contain null entries.
      Returns:
      The directories to clean or an empty array if none, never null.
    • toNullablePath

      private static Path toNullablePath(File file)