首页 > 其他分享 >What are the phases of the maven default lifecycle?

What are the phases of the maven default lifecycle?

时间:2023-07-02 18:00:49浏览次数:49  
标签:INFO What run 21 default maven phase test id

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

  1. validate
  2. generate-sources
  3. process-sources
  4. generate-resources
  5. process-resources
  6. compile
  7. process-classes
  8. generate-test-sources
  9. process-test-sources
  10. generate-test-resources
  11. process-test-resources
  12. test-compile
  13. test
  14. prepare-package (maven 2.1+)
  15. package
  16. pre-integration-test
  17. integration-test
  18. post-integration-test
  19. verify
  20. install
  21. 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

相关文章

  • IOS开发-NSUserDefaults的基本使用,缓存数据实现数据持久化
    NSUserDefaults是iOS与macOS中的一个存储对象。它用于存储应用程序运行期间和退出后需要保存的数据。NSUserDefaults的特点:-基于键值对:使用字符串作为键名存储数据。-支持的类型:NSString、NSNumber、NSDate、NSArray、NSDictionary等基本数据结构。-存储在本地:数据存储......
  • maven book
    selfexample.googlecode.com/files/Maven权威指南中文版.pdfhttp://www.sonatype.com/books/mvnref-book/pdf/mvnref-pdf.pdfhttp://code.google.com/p/door-county-software/downloads/detail?name=maven-definitive-guide.pdf ......
  • appassembler-maven-plugin useAllDependencies
    http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/assemble-mojo.htmlThefollowingcanbeusedtouseallprojectdependenciesinsteadofthedefaultbehaviorwhichrepresentsruntimedependenciesonly.forgoal:assembleitcanaddothersc......
  • Maven cheat sheet 手抄:从入门到无语
    Mavencheatsheet手抄写给懒人看的概念生命周期由阶段构成:validate,compile,test,package,verify,install,deploy基础基础编译:mvncleanpackage环境变量:MAVEN_HOME,MAVEN_OPTS,MAVEN_ARGS配置打印激活的配置:mvnhelp:active-profiles激活Profile:-Pprofi......
  • Unable to update index for central http://repo1.maven.org/maven2/
    Unable to update index for central http://repo1.maven.org/maven2/ 就是这句,myeclipse启动后控制台输出这句话:解决办法:1.在myeclipse3.4(我用的这个版本)里面Window => Preferences => Myeclipse Enterprise Workbench => Maven4Myeclipse => Maven=>禁用Downl......
  • Maven 入门实战(2)--POM
    POM(ProjectObjectModel,项目对象模型)是Maven工程的基本工作单元,它是一个XML文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖等等。执行任务或目标时,Maven会在当前目录中查找并读取POM,获取所需的配置信息,然后执行目标。1、基本配置<projectxmlns="http:......
  • Java中类 DefaultTableModel 的概念
    columnIdentifiers          Vector,由多个列标识符组成dataVector          Vector,由包含多个 Object 值的 Vector 组成。一个DefaultTableModel 就是一个二维表,以下是使用函数:DefaultTableModel()构造默认的DefaultTableModel,它是一个零......
  • Linux 安装 Maven
    一、概要1.环境(1)RockyLinux9.1(2)Maven3.9.3二、安装1.准备(1)下载安装包wgethttps://dlcdn.apache.org/maven/maven-3/3.9.3/binaries/apache-maven-3.9.3-bin.tar.gz(2)解压tar-zxvfapache-maven-3.9.3-bin.tar.gz2.安装(1)目录a.创建sudom......
  • What does the term epoch mean? Why it is so important?
    在人工智能中,"epoch"(中文称为"训练轮次"或"周期")是指训练神经网络时将整个训练数据集通过神经网络进行一次正向传播和反向传播的过程。每个"epoch"包含一次前向传播和一次后向传播,用于更新神经网络的参数。在每个"epoch"中,神经网络对整个训练数据集进行一次学习和优化,以逐渐提高......
  • Comparing with traditional convex optimization methodology, what are advantages
    与传统的凸优化方法相比,粒子群算法有哪些优点 与传统的凸优化方法相比,粒子群优化(PSO)算法具有以下优点:全局搜索能力:PSO算法具有较强的全局搜索能力,能够在多个解空间中寻找最优解。由于粒子群在搜索过程中可以通过信息共享和合作,有助于避免陷入局部最优解。适应性和......