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

(Continued from page 1)

Often, it can be a good practice to execute a "clean" before performing a phase in the default build lifecycle. This can minimize issues that can arise from not having an up-to-date target directory. As an example, below I created an External Tool Configuration to perform:

mvn clean install
External Tool Configuration for 'mvn clean install'

The output from "mvn clean install" on the "mytest" project is shown below. Notice that the clean phase is executed first (which we see via the clean:clean goal), followed by the phases/goals of the default lifecycle up to the install phase (via the install:install goal).

Console output from 'mvn clean install'

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mytest
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\mytest\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to C:\dev\workspace\mytest\target\classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 1 source file to C:\dev\workspace\mytest\target\test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: C:\dev\workspace\mytest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.maventest.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] Building jar: C:\dev\workspace\mytest\target\mytest-1.0-SNAPSHOT.jar
[INFO] [install:install]
[INFO] Installing C:\dev\workspace\mytest\target\mytest-1.0-SNAPSHOT.jar to \dev\m2repo\com\maventest\mytest\1.0-SNAPSHOT\mytest-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon Feb 04 17:20:57 PST 2008
[INFO] Final Memory: 12M/22M
[INFO] ------------------------------------------------------------------------
Page: < 1 2