1

I am using maven for the build purpose and normally we use the maven command mvn clean -Dmaven.test.skip=true package only to build the web application. I know we can use the mvn install command also to build a web application. But can anyone provide me with the exact difference between these two commands?

I found some notes on the clean and install commands. But i just want to know what's the advantage of using mvn clean command instead of using install command.

TKV
  • 2,533
  • 11
  • 43
  • 56
  • 1
    possible duplicate of [How is \*mvn clean install\* different from \*mvn install\*](http://stackoverflow.com/questions/6018701/how-is-mvn-clean-install-different-from-mvn-install) – grepit Sep 16 '14 at 21:03

3 Answers3

0

Maven has this concept of Maven Phases. Please go through the Maven Phases of this doc. So when you run a phase (say maven phase x) all the phases up to that phase is executed (that is phase 1 to phase x).

You need mvn clean to clean up artifacts created by prior builds. mvn package will package your code into your specified format in your POM. mvn install will also install the package made by Maven into the local repository.

Also note that clean and site are not part of phases of the default life-cycle. You have to fire it before your package or install command. Needless to say ordering does matter here.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
mandeep
  • 1
  • 3
  • There's also another page for Maven phases: [Introduction to the Build Lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#introduction-to-the-build-lifecycle) containing the section [Lifecycle Reference](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#lifecycle-reference). `site` hasn't to be called prior to default life-cycle phases, has it? – Gerold Broser Sep 17 '21 at 12:40
0

The main different between mvn clean -Dmaven.test.skip=true package and mvn install is that the first command line cleans the target directory and packages without running the tests. The second one compiles, tests, packages and installs the JAR or WAR file into the local repository at ~/.m2/repository.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • ... or POM file or any of [the core packaging types](https://maven.apache.org/pom.html#packaging) files or [custom packaging types](https://wiki.eclipse.org/Tycho/Packaging_Types#toc) files. – Gerold Broser Sep 12 '21 at 23:14
-1

As explained here.

clean is its own action in Maven. mvn clean install tell Maven to do the clean action in each module before running the install action for each module.

What this does is clear any compiled files you have, making sure that you're really compiling each module from scratch.

Community
  • 1
  • 1
Dark Knight
  • 8,218
  • 4
  • 39
  • 58
  • The term "action" isn't used in Maven for `clean`. There are four items named `clean`: `clean` lifecycle with its `clean` phase, `clean` [prefix](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) for the `maven-clean-plugin` with its `clean` goal. See also the comment to [this answer to _Maven: Lifecycle vs. Phase vs. Plugin vs. Goal_](https://stackoverflow.com/a/41466540/1744774). What you mean by _clean action_ and _install action_ here are Maven _phases_. – Gerold Broser Sep 17 '21 at 12:45