What is the difference between mvn clean install
and mvn install
?
5 Answers
clean
is its own build lifecycle phase (which can be thought of as an action or task) in Maven. 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.

- 1,851
- 5
- 17
- 23

- 87,612
- 17
- 125
- 175
-
22I always thought install including clean as one of its phase... until i see this – Junchen Liu Mar 17 '15 at 14:45
-
20@shanyangqu Sadly, no. `clean` is in a [separate lifecycle](http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference), so it's not called by default. – Powerlord Mar 17 '15 at 16:01
-
11. Re "_can be thought of as an action or task_": Maven phases are not _actions_ or _tasks_. If there's no plugin goal bound to a phase, neither an action nor a task, i.e. _nothing_ is done. A phase is more [a step or stage](https://stackoverflow.com/a/30953905/1744774). 2. Re "_do the `clean` phase_": With `mvn clean` it passes the `pre-clean` and the `clean` phase of the `clean` lifecycle and executes plugin goals bound to each phase. 3. Re "_clear any compiled files_": Not only those but everything that resides under `${project.build.directory}`: `
.jar`, resources, folders, etc. – Gerold Broser Nov 22 '20 at 02:37 -
1@JunchenLiu There are actually 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). – Gerold Broser Sep 17 '21 at 12:51
Maven lets you specify either goals or lifecycle phases on the command line (or both).
clean
and install
are two different phases of two different lifecycles, to which different plugin goals are bound (either per default or explicitly in your pom.xml)
The clean
phase, per convention, is meant to make a build reproducible, i.e. it cleans up anything that was created by previous builds. In most cases it does that by calling clean:clean
, which deletes the directory bound to ${project.build.directory}
(usually called "target")

- 292,901
- 67
- 465
- 588
-
7"install" is not a lifecycle. It's a phase in the default lifecycle. Though there is "clean" lifecycle, AFAIK this parameter specifies the "clean" phase in the "clean" lifecycle, not the "clean" lifecycle itself. – Puce May 16 '11 at 14:33
-
1
-
There are actually 4 items named `clean`: the lifecycle and one of its phases; the [plugin prefix](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) of the Maven Clean Plugin and one of its goals. – Gerold Broser Nov 22 '20 at 02:10
-
1
-
1@SeanPatrickFloyd :D A klan's Scherzerl, ha? ;-) OK, Monty Python... +1 – Gerold Broser Nov 24 '20 at 01:22
You can call more than one target goal with maven. mvn clean install
calls clean
first, then install
. You have to clean manually, because clean is not a standard target goal and not executed automatically on every install.
clean
removes the target folder - it deletes all class files, the java docs, the jars, reports and so on. If you don't clean
, then maven will only "do what has to be done", like it won't compile classes when the corresponding source files haven't changed (in brief).
we call it target in ant and goal in maven

- 113,398
- 19
- 180
- 268
-
3I think in this context clean and install are lifecycle phases, not goals. – JL_SO Aug 01 '19 at 13:35
-
1
-
`clean` doesn't _remove_ the `target` folder. It _cleans_ it. It's also not necessarily the folder named `target`, but the one defined by `${project.build.directory}`. – Gerold Broser Nov 22 '20 at 02:20
To stick with the Maven terms:
- "clean" is a phase of the clean lifecycle
- "install" is a phase of the default lifecycle
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

- 37,247
- 13
- 80
- 152
-
There are actually 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). – Gerold Broser Sep 17 '21 at 13:19
-
-
1Yes, it does. My comment was not meant to be criticism but additional information for all future readers and seekers here. – Gerold Broser Sep 18 '21 at 14:04
Ditto for @Andreas_D, in addition if you say update Spring from 1 version to another in your project without doing a clean, you'll wind up with both in your artifact. Ran into this a lot when doing Flex development with Maven.

- 2,441
- 19
- 22