gnodet opened a new pull request, #13291:
URL: https://github.com/apache/maven/pull/13291

   ## Problem
   
   After the move of `project-local-repo` from `target/project-local-repo` to 
`.mvn/target/project-local-repo` (PR #12650, fixes #12646), running `mvn clean` 
leaves an empty directory tree:
   
   ```
   .mvn/
     target/
       project-local-repo/   ← empty, but still present
   ```
   
   This is surprising to users who expect `mvn clean` to leave no remnants. 
Reported by Lenny Primak.
   
   ## Fix
   
   Extend the existing per-GAV cleanup in `cleanProjectLocalRepository()` to 
also prune the `project-local-repo` root and its parent (`.mvn/target`) when 
they become empty.
   
   The deletion uses `deleteIfEmpty()`, a small helper that calls 
`Files.deleteIfExists()` and silently ignores `DirectoryNotEmptyException`. 
This is inherently race-free:
   - The deletion only succeeds when the directory is empty
   - An empty directory cannot be concurrently written to (artifact installs 
create subdirectories first)
   - No locking needed
   
   ## Behavior after this fix
   
   | Scenario | Before | After |
   |---|---|---|
   | `mvn clean` (full reactor) | Empty `.mvn/target/project-local-repo` dir 
remains | Directory tree removed entirely ✓ |
   | `mvn clean -pl :A` | Empty dirs if A was the only module | Dirs removed 
only if no other modules have artifacts ✓ |
   | `mvn clean -pl :A` with sibling artifacts | Sibling entries preserved | 
Sibling entries preserved, dirs kept ✓ |
   | `mvn clean install` (concurrent) | No race (already fixed by #12650) | No 
race ✓ |
   
   The fix for #12646 (race condition) is not affected — `.mvn/target/` is 
still never touched by `maven-clean-plugin`.


-- 
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