The phases of the default (build) mavenSW lifecycle are listed at http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle. I have listed them again here:
Maven Default Lifecycle Phases
- validate
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
- process-classes
- generate-test-sources
- process-test-sources
- generate-test-resources
- process-test-resources
- test-compile
- test
- prepare-package (maven 2.1+)
- package
- pre-integration-test
- integration-test
- post-integration-test
- verify
- install
- deploy
Notice that there are actually 21 phases of the default lifecycle listed. The "prepare-package" phase, however, won't be used until maven 2.1+. Since I am running 2.0.8 (the latest version at the time of this writing), this phase is not available to me.
There are a couple key concepts to be aware of with maven lifecycles. First off, if we call a particular phase via a maven command, such as "mvn compile", all phases up to and including that phase will be executed. So, in the case of "mvn compile", we would actually go through the validate, generate-sources, process-sources, generate-resources, process-resources, and compile phases. The second main concept to be aware of in regards to lifecycles is that, based on the packaging of a project (jar, warW, earW, etc), different maven goals will be bound to different phases of the maven lifecycle.
Let's demonstrate the phases of the maven default lifecycle. One way to do this is to bind the antrun:run goal to the various phases of the maven default lifecycle, and to output a message using the AntSW echo task. Here, I created a pom.xml file that will output a message for each phase of the default lifecycle.
pom.xml file that binds antrun:run to default lifecycle phases
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maventest</groupId>
<artifactId>aproject</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>aproject</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>id.validate</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in validate phase (1 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in generate-sources phase (2 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.process-sources</id>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in process-sources phase (3 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.generate-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in generate-resources phase (4 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.process-resources</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in process-resources phase (5 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in compile phase (6 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in process-classes phase (7 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.generate-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in generate-test-sources phase (8 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.process-test-sources</id>
<phase>process-test-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in process-test-sources phase (9 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.generate-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in generate-test-resources phase (10 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.process-test-resources</id>
<phase>process-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in process-test-resources phase (11 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in test-compile phase (12 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in test phase (13 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.prepare-package</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in prepare-package phase (14 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in package phase (15 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in pre-integration-test phase (16 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in integration-test phase (17 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in post-integration-test phase (18 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.verify</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in verify phase (19 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.install</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in install phase (20 of 21)</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.deploy</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in deploy phase (21 of 21)</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<extensions>
<!-- begin - needed for deploying to repository using webdav -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
<!-- end - needed for deploying to repository using webdav -->
</extensions>
</build>
<distributionManagement>
<repository>
<id>archiva.internal</id>
<name>Internal Release Repository</name>
<url>dav:http://192.168.1.7:8081/archiva/repository/internal</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<name>Internal Snapshot Repository</name>
<url>dav:http://192.168.1.7:8081/archiva/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
Now, let's try a "mvn deploy" on the project containing the above pom.xml file. The deploy phase is the last phase of the default lifecycle. Since it is the last phase, all phases of the lifecycle will be executed.
Console output from 'mvn deploy'
[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO] task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: id.validate}]
[INFO] Executing tasks
[echo] in validate phase (1 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.generate-sources}]
[INFO] Executing tasks
[echo] in generate-sources phase (2 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.process-sources}]
[INFO] Executing tasks
[echo] in process-sources phase (3 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.generate-resources}]
[INFO] Executing tasks
[echo] in generate-resources phase (4 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.process-resources}]
[INFO] Executing tasks
[echo] in process-resources phase (5 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.compile}]
[INFO] Executing tasks
[echo] in compile phase (6 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.process-classes}]
[INFO] Executing tasks
[echo] in process-classes phase (7 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.generate-test-sources}]
[INFO] Executing tasks
[echo] in generate-test-sources phase (8 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.process-test-sources}]
[INFO] Executing tasks
[echo] in process-test-sources phase (9 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.generate-test-resources}]
[INFO] Executing tasks
[echo] in generate-test-resources phase (10 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.process-test-resources}]
[INFO] Executing tasks
[echo] in process-test-resources phase (11 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.test-compile}]
[INFO] Executing tasks
[echo] in test-compile phase (12 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.test}]
[INFO] Executing tasks
[echo] in test phase (13 of 21)
[INFO] Executed tasks
[INFO] [site:attach-descriptor]
[INFO] [antrun:run {execution: id.package}]
[INFO] Executing tasks
[echo] in package phase (15 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.pre-integration-test}]
[INFO] Executing tasks
[echo] in pre-integration-test phase (16 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.integration-test}]
[INFO] Executing tasks
[echo] in integration-test phase (17 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.post-integration-test}]
[INFO] Executing tasks
[echo] in post-integration-test phase (18 of 21)
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.verify}]
[INFO] Executing tasks
[echo] in verify phase (19 of 21)
[INFO] Executed tasks
[INFO] [install:install]
[INFO] Installing C:\dev\workspace\aproject\pom.xml to \dev\m2repo\com\maventest\aproject\1.0-SNAPSHOT\aproject-1.0-SNAPSHOT.pom
[INFO] [antrun:run {execution: id.install}]
[INFO] Executing tasks
[echo] in install phase (20 of 21)
[INFO] Executed tasks
[INFO] [deploy:deploy]
altDeploymentRepository = null
[INFO] Retrieving previous build number from archiva.snapshots
Uploading: http://192.168.1.7:8081/archiva/repository/snapshots/com/maventest/aproject/1.0-SNAPSHOT/aproject-1.0-20080213.235441-1.pom
4096/?
7950/?
[INFO] Retrieving previous metadata from archiva.snapshots
[INFO] Uploading repository metadata for: 'snapshot com.maventest:aproject:1.0-SNAPSHOT'
[INFO] Retrieving previous metadata from archiva.snapshots
[INFO] Uploading repository metadata for: 'artifact com.maventest:aproject'
[INFO] [antrun:run {execution: id.deploy}]
[INFO] Executing tasks
[echo] in deploy phase (21 of 21)
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Wed Feb 13 15:54:42 PST 2008
[INFO] Final Memory: 8M/15M
[INFO] ------------------------------------------------------------------------
From the output, notice that all phases of the lifecycle are executed. Notice that the "prepare-package" phase (14 of 21) does not occur since I'm not using maven 2.1 (since it hasn't been released at the time of this writing).
标签:INFO,What,run,21,default,maven,phase,test,id From: https://blog.51cto.com/u_16174476/6606374