The Maven Clean Plugin removes all the resources like files and directories created during the previous build. It also cleans up the target directory by default.
Goal:
The Clean Plugin only has one goal.
clean:clean attempts to clean a project’s working directory of the files that we’re 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.
Configuration:
1. Delete additional files from a directory – Following configuration will add additional directory to be cleaned up. It will also include some specific file types and exclude some files which will not be cleaned up.
<build> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> <configuration> <filesets> <fileset> <directory>results</directory> <includes> <include>**/*.html</include> <include>**/*.json</include> </includes> <excludes> <exclude>**/cucumber.html</exclude> <exclude>**/cucumber.json</exclude> </excludes> </fileset> </filesets> </configuration> </plugin> </plugins> </build>
2. Skip Clean – The following configuration will skip running the cleanup.
<build> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build
3. Ignore errors – The following configuration will ignore all errors occurred during cleanup.
<build> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> <configuration> <failOnError>false</failOnError> </configuration> </plugin> <plugins> </build>