Maven failing to clean project: Failed to delete file. | Community
Skip to main content
New Participant
January 29, 2025
Solved

Maven failing to clean project: Failed to delete file.

  • January 29, 2025
  • 6 replies
  • 11016 views

I have been facing an issue for a long time with the following command: 

 

mvn clean install -PautoInstallSinglePackage

 

Sometimes it runs and just works. Other times it fails with this error:

 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.0.0:clean (default-clean) on project aem-mysite-project.ui.apps: Failed to clean project: Failed to delete C:\git\MySite\ui.apps\target\generated-sources\htl\org\apache\sling\scripting\sightly\apps\mysite\components\tabs\tabs__002e__html.java -> [Help 1]

 

The failure is seemingly random. It happens on various files, but it happens daily. I've been trying to chase this down, and I've been able to identify via an app called LockHunter.exe that the "Language Support for Java" plugin for VSCode by Red Hat is the culprit.

 

Does anyone have a solution for this? Are there alternative plugins for VSCode that can be used to easily work with AEM/Java projects from VSCode?  Maybe a command I can pass to maven to get it to unlock?

Best answer by aanchal-sikka

@dylanmccurry 

 

Could you possibly be accessing the project's target through multiple applications at the same time? Like IDE + Windows Explorer etc. If yes, please close other applications before rebuilding the code.

 

In case it persists, close all applications accessing target folder. Delete target folder manually, then rebuild the code.

6 replies

PGURUKRISHNA
New Participant
August 18, 2025

 

Hi @dylanmccurry,

Please close VS Code completely and then run the following command directly in your local terminal:

 

 
mvn clean install -DskipTests -PautoInstallPackage -U \ "-Daem.host=localhost" \ "-Daem.port=4502" \ "-Dsling.username=admin" \ "-Dsling.password=admin" \ "-DAUTHOR_IP=localhost"
 

This issue occurs because VS Code sometimes blocks certain processes required for the build. Running the command in the terminal after closing VS Code ensures the installation works without errors.

 

Thanks!

Guru Krishna.

chaudharynick
New Participant
February 3, 2025

Hi @dylanmccurry 

 

I would recommend using IntelliJ as this won't come up over there. or whenever such issue happens you can either manually delete the target folder or restart the vs code and it will work.

AmitVishwakarma
New Participant
February 2, 2025

To fix the Maven clean error:

1. Manually delete the target folder and run mvn clean install again.
2. Close VSCode and any other apps accessing the project directory.
3. Try running Maven with:

mvn clean install -Dmaven.clean.failOnError=false -PautoInstallSinglePackage


4. Restart your system if the issue persists.
Also, ensure the VSCode Java plugin is up to date or consider trying a different one.

 

aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
January 30, 2025

@dylanmccurry 

 

Could you possibly be accessing the project's target through multiple applications at the same time? Like IDE + Windows Explorer etc. If yes, please close other applications before rebuilding the code.

 

In case it persists, close all applications accessing target folder. Delete target folder manually, then rebuild the code.

Aanchal Sikka
ayush-anand
New Participant
January 29, 2025

Hi @dylanmccurry 

 

Try manually deleting the target folder from the ui.apps module and then run mvn clean install again. If that doesn’t work, run mvn clean separately before trying the build. Also, check if any program like an IDE (IntelliJ, Eclipse, VS Code) is using the folder—close it and any open terminals before retrying. If the issue persists, restarting your system might help.

 

Regards

Ayush

Tethich
New Participant
January 29, 2025

Hi @dylanmccurry 

 

The only options I am aware of are:


1. Manually delete the target folder from your project

2. Restart the IDE, in your case VSCode

3. Run Maven one time with -Dmaven.clean.failOnError=false parameter