How do I use the maven clean phase?
Author: Deron Eriksson
Description: This tutorial describes how to use the maven clean phase.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)

Page:    1 2 >

MavenSW has three lifecycles: clean, default, and site. If a particular phase of a lifecycle is called, such as "test" of the default lifecycle, all phases up to and including that phase would be called. However, in this example, no phases in the clean and site lifecycles would be called as a result of a "mvn test" since this phase is in the default lifecycle, which is a separate lifecycle from the clean lifecycle and site lifecycle.

The clean lifecycle has three phases: pre-clean, clean, and post-clean. Usually, we just use the clean phase, which by default deletes the project's build directory and its contents, which by mavenSW default is the "target" directory.

So, to 'clean' a project, we in general just do:

mvn clean

I created an EclipseSW External Tool Configuration to let me select a project and then click on the External Tool Configuration to execute a "mvn clean" on the project:

External Tool Configuration for 'mvn clean'

I selected the "mytest" project and selected the "mvn clean" External Tool Configuration to execute a "mvn clean" on the selected project.

Executing 'mvn clean' on 'mytest' project

The console output from "mvn clean" is shown below. Notice that C:\dev\workspace\mytest\target gets deleted.

Console output from 'mvn clean'

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mytest
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\mytest\target
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Feb 04 16:52:19 PST 2008
[INFO] Final Memory: 3M/5M
[INFO] ------------------------------------------------------------------------

In the Eclipse Navigator, we can see that most of the contents of "target" are gone. Actually, all of the contents were deleted, but after this happened, Eclipse recreated the target/classes and target/test-classes directories since they are output directories specified in the project's .classpath file.

Project has been cleaned

(Continued on page 2)

Page:    1 2 >