Class CleanOrphansMojo
- All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
When a sub-project is removed from the reactor (e.g. after a git pull or a branch
switch), its target/ directory may remain on disk even though its pom.xml is
gone. Because the sub-project is no longer part of the reactor, mvn clean cannot know
about it and will skip it. This goal detects such orphaned directories and removes them.
Detection heuristic: a direct child directory of the current project's basedir is
considered orphaned when its only non-hidden child is the build output directory
(typically target/). A freshly checked-out or live sub-project always has at least a
pom.xml alongside its build directory, so a directory whose sole visible content is a
target/ folder can safely be assumed to be a leftover. The entire child directory
(not just its build output subdirectory) is removed, since an orphaned directory with no
source files has no reason to remain on disk.
- Since:
- 4.0.0-beta-3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Scans direct children of the projectbasedirfor orphaned build output directories and deletes them.
-
Constructor Details
-
CleanOrphansMojo
public CleanOrphansMojo()
-
-
Method Details
-
execute
public void execute()Scans direct children of the projectbasedirfor orphaned build output directories and deletes them.- Specified by:
executein interfaceorg.apache.maven.api.plugin.Mojo- Throws:
org.apache.maven.api.plugin.MojoException- if an orphaned directory cannot be deleted andfailOnErroristrue
-