tags:

views:

603

answers:

8

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] ------------------------------------------------------------------------
+3  A: 

Often you run into this problem when on Windows because Windows doesn't (ordinarily) allow you to delete a file which is in use. Aside from (painfully) going through all your Maven configuration, your best bet is just not to build on Windows (e.g. use a Linux/Solaris/whatever VM).

Nicholas Riley
+6  A: 

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

Ken Liu
I am using Eclipse with Maven integration, but for some reason I am still using the command line to clean and build. I'll try cleans within Eclipse and see if I get the same results.
hoffmandirt
A: 

That's because you block target directory (open a file or enter into (sub)directory of target dir, or any other process/app uses file from this dir). If windows delete command also complains it's not maven fault.

cetnar
+1  A: 

I'm guessing you are opening files in a text editor or leaving a shell open on a directory in target. If some process has a lock on a file or folder Windows won't let you delete it.

If you run a tool like wholockme you'll be able to see what process is locking the file.

Rich Seller
+1  A: 

I had the same problem with builds run from Hudson.

Using handle.exe (from Sysinternals) I found out that a java.exe task has an active filehandle to the generated jar file.

If I kill this task the next build succeds. But the next build after this successful build fails again with the same error.

Even if the build task succeeds, it seems not to terminate properly and keeps files open.

I'm a beginner with Hudson and I didn't have this problem at first. Then I played with some plugins and later this problem come up and was reproduceable.

I deactivated almost all plugins (kept only some essential ones like subversion and sonar) and now the problem seems to be solved.

Hope this helps a bit ...

zoechi
A: 

The problem is eclipse is constantly reading the directories and artifacts in your maven project and inevitably has one of them open when you are cleaning.

The best approach is to run maven clean from the eclipse plugin (I use m2eclipse and this seems to work well).

Another approach that sort of works is to run mvn clean with the maven.clean.failOnError flag set to false. If you run it twice usually that is enough to make everything work properly, e.g.

mvn clean -Dmaven.clean.failOnError=false && mvn clean -Dmaven.clean.failOnError=false

You will probably want to turn off eclipse's "Build automatically" from the project menu while you do that.

Dean Povey
A: 

Try to disable Windows Indexing Service.

Andrey Tyukavkin
A: 

Turning off Window Search service on Win7 worked for me

JCameron