Skip to main content
Level 4
Jan 29, 2025 7:35 PM UTC
Solved

Maven failing to clean project: Failed to delete file.

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?

aanchal-sikka
aanchal-sikkaAccepted solution
Community Advisor
Jan 30, 2025 3:08 AM UTC

@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

6 replies

Tethich
Community Advisor
Community Advisor
Jan 29, 2025 8:03 PM UTC

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

Translate
ayush-anand
Level 4
Jan 29, 2025 11:11 PM UTC

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

Translate
aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
Jan 30, 2025 3:08 AM UTC

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

Translate
Aanchal Sikka
AmitVishwakarma
Community Advisor
Community Advisor
Feb 2, 2025 5:25 AM UTC

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.

 

Translate
Amit Vishwakarma - Adobe Commerce Champion 2025 | 17x Adobe certified | 6x Adobe SME
chaudharynick
Adobe Champion
Adobe Champion
Feb 3, 2025 5:17 PM UTC

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.

Translate
PGURUKRISHNA
Level 5
Aug 18, 2025 9:09 AM UTC

 

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.

Translate
Pagidala GuruKrishna