Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use mvn clean install instead of mvn install?

Tags:

java

maven

I have a web application that is packaged as a war file ( including several jar files ). I noticed that when I run mvn install - the only projects that are compiled are those who have changed - then it replaces these jars in the war file.

If that's the case - when should I use mvn clean install instead of simply use mvn install?

I guess that if I change any resources than I would have to use mvn clean install - Am I right?

And if I'm right, then whenever I only change classes, is mvn install good enough?

like image 232
Noam Avatar asked Dec 24 '12 17:12

Noam


2 Answers

Mostly, the only reason to do a clean is if you do something that would remove or rename a class or resource in the output directory, such as renaming a .java file or changing something that generates classes so that it generates them with different names. In those cases, the old class or resource files will still exist in the output directory and may cause strange behavior.

Other than that, just use install, and you'll be fine. Then Maven will only build what needs to be built to bring the output directories up to date.

like image 81
Ryan Stewart Avatar answered Oct 23 '22 00:10

Ryan Stewart


Use clean when you want to build your projects from scratch. If your build does not take a lot of time use clean every time you are running build. Otherwise it is up to you.

Surely do it if you are not sure that everything is indeed updated.

like image 38
AlexR Avatar answered Oct 22 '22 22:10

AlexR