gnodet opened a new pull request, #356:
URL: https://github.com/apache/maven-clean-plugin/pull/356

   ## Summary
   
   Adds a new `purge-check` goal to detect and remove orphaned build output 
directories left behind by sub-projects that have been removed from the reactor.
   
   ## Problem
   
   When a sub-project is removed from the reactor (e.g. after `git pull` or a 
branch switch), its `target/` directory may remain on disk. Since the 
sub-project is no longer in the reactor, `mvn clean` cannot know about it and 
skips it. This causes issues with plugins that scan the project tree 
recursively — notably **RAT** which finds unlicensed build artifacts and fails 
the build.
   
   See #315, 
[apache/maven-resolver#1943](https://github.com/apache/maven-resolver/issues/1943),
 [apache/maven#11800](https://github.com/apache/maven/issues/11800).
   
   ## Solution
   
   New goal `clean:purge-check` with heuristic:
   
   > A direct child directory of `basedir` is considered orphaned when its 
**only non-hidden child** is the build output directory (typically `target/`). 
A live sub-project always has at least a `pom.xml` alongside its build 
directory.
   
   This avoids false positives while covering the exact scenario of a removed 
sub-project (which leaves only a `target/` behind).
   
   The goal uses NIO2 (`DirectoryStream`, `Files.isDirectory`), respects 
`${project.build.directory}` for the build dir name, and reuses the existing 
`Cleaner` for deletion.
   
   ## Lifecycle integration
   
   This PR only adds the goal. The binding to the `initialize` phase of the 
default lifecycle will be done separately in **Maven core 4.1.0**, so it runs 
automatically on every build (not just `mvn clean`), preventing stale artifacts 
from interfering with RAT, Checkstyle, etc.
   
   Users on earlier Maven versions can bind it manually:
   
   ```xml
   <execution>
     <id>purge-check</id>
     <phase>initialize</phase>
     <goals><goal>purge-check</goal></goals>
   </execution>
   ```
   
   ## Changes
   
   - `CleanOrphansMojo` — new mojo, NIO2, reuses `Cleaner`
   - `src/it/purge-check-orphan/` — IT: creates an orphaned 
`sub-orphan/target/` via `setup.groovy`, verifies it is removed while 
`sub-existing/target/` (which has siblings) is left intact
   
   Fixes #315


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to