What are the phases of the maven site lifecycle?
Author: Deron Eriksson
Description: This tutorial shows the phases of the maven site lifecycle.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


The mavenSW site lifecycle consists of the following four phases:

Maven Site Lifecycle Phases

  1. pre-site
  2. site
  3. post-site
  4. site-deploy

Calling one phase of the site lifecycle results in the execution of all phases up to an including that phase. If we execute a "mvn site" command, we will execute the pre-site and site phases. If we perform a "mvn site-deploy", we will execute the pre-site, site, post-site, and site-deploy phases.

The maven "site:site" goal is typically bound to the site phase, and the maven "site:deploy" goal is bound to the site-deploy phase. The pre-site and post-site phases typically aren't used, but they can be utilized to perform and kind of pre-documentation or post-documentation tasks, and the post-site phase could potentially be used for any tasks required prior to a site deployment.

In typical use, you'll perform a "mvn clean site" to clean a project and generate fresh documentation, and you'll perform a "mvn clean site-deploy" to clean a project, generate a site, and deploy that site. The "clean" phase is actually a phase in the clean lifecycle, which cleans up the build (target) directory, which usually consists of deleting the contents of the target directory. So, a "mvn clean site" actually performs the pre-clean and clean phases of the clean lifecycle and then performs the pre-site and site phases of the site lifecycle. A "mvn clean site-deploy" performs the pre-clean and clean phases of the clean lifecycle followed by the pre-site, site, post-site, and site-deploy phases of the site lifecycle.

To highlight the phases of the site lifecycle, I bound the maven-antrun-plugin:run goal to the phases of the site lifecycle so that a message will be output for each phase of the lifecycle.

pom.xml file that binds antrun:run to the site 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.pre-site</id>
						<phase>pre-site</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>
								<echo>in pre-site phase</echo>
							</tasks>
						</configuration>
					</execution>
					<execution>
						<id>id.site</id>
						<phase>site</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>
								<echo>in site phase</echo>
							</tasks>
						</configuration>
					</execution>
					<execution>
						<id>id.post-site</id>
						<phase>post-site</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>
								<echo>in post-site phase</echo>
							</tasks>
						</configuration>
					</execution>
					<execution>
						<id>id.site-deploy</id>
						<phase>site-deploy</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>
								<echo>in site-deploy phase</echo>
							</tasks>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
		<extensions>
			<extension>
				<groupId>org.apache.maven.wagon</groupId>
				<artifactId>wagon-webdav</artifactId>
				<version>1.0-beta-2</version>
			</extension>
		</extensions>
	</build>
	<distributionManagement>
		<site>
			<id>site.deployments</id>
			<name>Site deployments</name>
			<url>dav:http://192.168.1.7/sites/${project.artifactId}/</url>
		</site>
	</distributionManagement>
</project>

If we perform a "mvn clean site" on the project with the above pom.xml, we can see that the pre-site and site phases are executed based on our messages.

Console output from 'mvn clean site'

[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO]    task-segment: [clean, site]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\aproject\target
[INFO] [antrun:run {execution: id.pre-site}]
[INFO] Executing tasks
     [echo] in pre-site phase
[INFO] Executed tasks
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [site:site]
[INFO] Generating "Continuous Integration" report.
[INFO] Generating "Dependencies" report.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project License" report.
[INFO] Generating "Mailing Lists" report.
[INFO] Generating "About" report.
[INFO] Generating "Project Summary" report.
[INFO] Generating "Source Repository" report.
[INFO] Generating "Project Team" report.
[INFO] [antrun:run {execution: id.site}]
[INFO] Executing tasks
     [echo] in site phase
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Thu Feb 14 13:57:22 PST 2008
[INFO] Final Memory: 13M/28M
[INFO] ------------------------------------------------------------------------

Now, I'll perform a "mvn clean site-deploy" on the same project.

Console output from 'mvn clean site-deploy'

[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO]    task-segment: [clean, site-deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\aproject\target
[INFO] [antrun:run {execution: id.pre-site}]
[INFO] Executing tasks
     [echo] in pre-site phase
[INFO] Executed tasks
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [site:site]
[INFO] Generating "Continuous Integration" report.
[INFO] Generating "Dependencies" report.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project License" report.
[INFO] Generating "Mailing Lists" report.
[INFO] Generating "About" report.
[INFO] Generating "Project Summary" report.
[INFO] Generating "Source Repository" report.
[INFO] Generating "Project Team" report.
[INFO] [antrun:run {execution: id.site}]
[INFO] Executing tasks
     [echo] in site phase
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.post-site}]
[INFO] Executing tasks
     [echo] in post-site phase
[INFO] Executed tasks
[INFO] [site:deploy]
http://192.168.1.7/sites/aproject/ - Session: Opened  
Uploading: ./css/maven-base.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2371 bytes copied in 0.014 seconds
Uploading: ./css/maven-theme.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2801 bytes copied in 0.0090 seconds
Uploading: ./css/print.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 222 bytes copied in 0.0090 seconds
Uploading: ./css/site.css to http://192.168.1.7/sites/aproject/


Transfer finished. 0 bytes copied in 0.0070 seconds
Uploading: ./dependencies.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 5175 bytes copied in 0.013 seconds
Uploading: ./images/collapsed.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 53 bytes copied in 0.0080 seconds
Uploading: ./images/expanded.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 52 bytes copied in 0.012 seconds
Uploading: ./images/external.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 230 bytes copied in 0.0080 seconds
Uploading: ./images/icon_error_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1010 bytes copied in 0.0080 seconds
Uploading: ./images/icon_info_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 606 bytes copied in 0.0080 seconds
Uploading: ./images/icon_success_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 990 bytes copied in 0.0080 seconds
Uploading: ./images/icon_warning_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 576 bytes copied in 0.012 seconds
Uploading: ./images/logos/build-by-maven-black.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2294 bytes copied in 0.0090 seconds
Uploading: ./images/logos/build-by-maven-white.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2260 bytes copied in 0.014 seconds
Uploading: ./images/logos/maven-feather.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3330 bytes copied in 0.0090 seconds
Uploading: ./images/newwindow.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 220 bytes copied in 0.013 seconds
Uploading: ./index.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3733 bytes copied in 0.0090 seconds
Uploading: ./integration.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3779 bytes copied in 0.0090 seconds
Uploading: ./issue-tracking.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3743 bytes copied in 0.01 seconds
Uploading: ./license.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3726 bytes copied in 0.01 seconds
Uploading: ./mail-lists.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3754 bytes copied in 0.012 seconds
Uploading: ./project-info.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 5771 bytes copied in 0.01 seconds
Uploading: ./project-summary.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 4552 bytes copied in 0.01 seconds
Uploading: ./source-repository.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3761 bytes copied in 0.01 seconds
Uploading: ./team-list.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 4894 bytes copied in 0.013 seconds
http://192.168.1.7/sites/aproject/ - Session: Disconnecting  
http://192.168.1.7/sites/aproject/ - Session: Disconnected
[INFO] [antrun:run {execution: id.site-deploy}]
[INFO] Executing tasks
     [echo] in site-deploy phase
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Thu Feb 14 13:57:58 PST 2008
[INFO] Final Memory: 13M/28M
[INFO] ------------------------------------------------------------------------

From the output, notice that all phases of the site lifecycle (pre-site, site, post-site, and site-deploy) get executed as a result of the call to site-deploy.


Related Tutorials: