Maven Clean Lifecycle Phases
pre-clean
clean
post-clean
Calling one phase of the clean lifecycle results in the execution of all phases up to an including that phase. So, if we perform a "mvn clean", we will execute the pre-clean and the clean phases. If we perform a "mvn post-clean", we will execute the pre-clean, clean, and post-clean phases.
The maven "clean:clean" goal is typically bound to the clean phase. This goal 'cleans' the project's build (usually 'target') directory, which typically involves deleting old files. The pre-clean phase can be used for any tasks required prior to cleanup, and the post-clean phase can be used for tasks following the cleanup.
We can bind other goals to the phases of the clean lifecycle. In the following pom.xml file, I bind the maven-antrun-plugin:run goal to the pre-clean, clean, and post-clean phases. This will allow me to echo text messages displaying the phases of the clean lifecycle.
pom.xml file that binds antrun:run to pre-clean, clean, and post-clean 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-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in pre-clean phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.clean</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in clean phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.post-clean</id>
<phase>post-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>in post-clean phase</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If we perform a "mvn clean" on the project with the above pom.xml, we can see that the pre-clean and clean phases are executed based on our text messages.
Console output from 'mvn clean'
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO] task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: id.pre-clean}]
[INFO] Executing tasks
[echo] in pre-clean phase
[INFO] Executed tasks
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\aproject\target
[INFO] [antrun:run {execution: id.clean}]
[INFO] Executing tasks
[echo] in clean phase
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Feb 13 14:44:26 PST 2008
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------
If we perform a "mvn post-clean" on the project, we can see that the pre-clean, clean, and post-clean phases are all executed.
Console output from 'mvn post-clean'
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO] task-segment: [post-clean]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: id.pre-clean}]
[INFO] Executing tasks
[echo] in pre-clean phase
[INFO] Executed tasks
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\aproject\target
[INFO] [antrun:run {execution: id.clean}]
[INFO] Executing tasks
[echo] in clean phase
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.post-clean}]
[INFO] Executing tasks
[echo] in post-clean phase
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Feb 13 14:44:55 PST 2008
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
分享到:
相关推荐
Gradle, on the other hand, combines the flexibility of Ant with some of the automation features of Maven, using a Groovy-based DSL instead of XML. **1.7 Comparing Maven with Ant** Ant is another ...
Selecting a number of phases can increase component counts and costs, which begs the question, how many phases are needed? What benefit do a given number of phases for a certain power requirement ...
have provided basic insights into the structure and bulk properties of condensed phases of matter, including low-temperature states (e.g., molecular and colloidal liquids, crystals, and glasses), ...
(b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...
2. **生命周期 (Lifecycle)**: Maven的生命周期包括一系列阶段(phases),如clean、validate、compile、test、package、install和deploy,这些阶段按顺序执行,构建并管理整个项目流程。 3. **插件 (Plugins)**: ...
- **生命周期(Lifecycle)**:Maven 有三个主要的生命周期:clean、default和site,分别对应清理、构建和站点生成。 - **构建阶段(Phases)**:每个生命周期由多个阶段组成,如compile、test、install等,它们按...
This fully packed mini-book includes the new features and enhancements found in the latest version of Maven. In this short 100-page book, you'll learn all about Maven and how to set it up to use. ...
At this point, we're not developing or accepting new ... If you bind the default phases, when you type mvn package, you get a Docker image. When you type mvn deploy, your image gets pushed. Make t
**构建生命周期**由一系列预定义的目标(phases)组成,如clean、compile、test、package、install和deploy。开发者可以根据需求选择执行生命周期中的特定阶段。Maven 3.6在生命周期管理上更加智能,错误处理和日志...
洛施密特回波(Loschmidt echo)在 Lipkin-Meshkov-Glick 模型两相中的不同衰减行为,王评,王骞,在 Lipkin-Meshkov-Glick (LMG) 模型的量子相变点附近导出了在对称相与破缺相都适用的 Loschmidt echo (LE) 的一个...
6. **生命周期(Lifecycle)与构建阶段(Phases)** Maven的生命周期包括`clean`、`default`(或`compile`)、`install`和`deploy`等阶段。每个阶段由一系列目标(goals)组成,如`clean:clean`、`compile:compile`...
Multi-core processors ... However, part of the tool support is lacking and more has to be done, as future work, to replace some of the phases which are now developed by hand with (semi-)automated tools.
4. **生命周期(Lifecycle)**: Maven有三个主要的生命周期:clean、default和site。clean用于清理项目,default用于构建项目,site用于生成项目报告和站点。 5. **构建阶段(Phases)**: 生命周期由一系列阶段(如...
Maven 构建生命周期由多个阶段(phases)组成,主要包括清理(clean)、初始(initialize)、编译(compile)、测试(test)、打包(package)、验证(verify)、集成测试(integration-test)、部署(install)、...
Maven 的生命周期由一系列阶段(phases)组成,如清理(clean)、编译(compile)、测试(test)、打包(package)、验证(verify)、安装(install)和部署(deploy)。开发者可以通过`mvn <phase>`命令执行特定...
Maven生命周期由一系列阶段(phases)组成,如`clean`、`validate`、`compile`、`test`、`package`、`install`和`deploy`。每个阶段都有一系列绑定的构建目标(goals)。例如,`mvn compile`会执行从`validate`到`...
Maven通过命令行接口(CLI)提供了一系列的生命周期阶段(Lifecycle Phases),例如`clean`、`compile`、`test`、`package`、`install`和`deploy`等。开发者可以通过执行这些命令来完成项目的不同阶段操作。例如,`...
- 在执行构建时,Maven会按照生命周期的顺序执行目标(phases)。 - Maven会自动解决依赖关系,将所有依赖项加入到项目中。 3. **Maven安装与配置** - 下载Maven安装包,例如`apache-maven-3.0.5`,解压到指定...
In the first two test phases, the ALO algorithm is compared with a variety of algorithms in the literature. The results of the test functions prove that the proposed algorithm is able to provide very...