Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Maven's mvn clean ever work the first time?

Tags:

maven-2

Nine times out of ten when I run mvn clean on my projects I experience a build error. I have to execute mvn clean multiple times until the build error goes away. Does anyone else experience this? Is there any way to fix this within Maven? If not, how do you get around it? I wrote a bat file that deletes the target folders and that works well, but it's not practical when you are working on multiple projects. I am using Maven 2.2.1.

[ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to delete directory: C:\Documents and Settings\user\My Documents\software-developm ent\a\b\c\application-domain\target. Reason: Unable to delete directory C:\Documen ts and Settings\user\My Documents\software-development\a\b\c\application-domai n\target\classes\com\a\b  [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6 seconds [INFO] Finished at: Fri Oct 23 15:22:48 EDT 2009 [INFO] Final Memory: 11M/254M [INFO] ------------------------------------------------------------------------ 
like image 807
Dan Polites Avatar asked Oct 23 '09 19:10

Dan Polites


People also ask

How do I run after maven clean install?

Once you have this installed, you should be able to run all the maven commands. To do so, from the package explorer, you would right click on either the maven project or the pom. xml in the maven project, highlight Run As, then click Maven Install. Hope this helped.

How does mvn clean work?

mvn clean install tells Maven to do the clean phase in each module before running the install phase for each module. What this does is clear any compiled files you have, making sure that you're really compiling each module from scratch.

How use mvn clean command?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project.


2 Answers

It may be that your IDE or some other process is holding on to the the "target" folder and preventing maven from deleting it.

like image 129
Ken Liu Avatar answered Oct 16 '22 15:10

Ken Liu


This is mostly caused by Windows Indexing. Excluding target folders or .jar extention from indexing will fix the problem. My best practice is excluding .jar extention.

To exclude target files:

  1. Click on windows icon/start menu
  2. Type indexing in search box and click on Indexing Options
  3. Then click on Modify button to investigate directories indexing.
  4. Remove checks of Target folders.

To excluse all .jar files:

  1. Click on windows icon/start menu
  2. Type indexing in search box and click on Indexing Options
  3. Then click on Advanced button.
  4. Go through File Types tab.
  5. In the list, find jar and uncheck it.
like image 30
Ediz Türkoğlu Avatar answered Oct 16 '22 15:10

Ediz Türkoğlu