16)maven lifecycle
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
http://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html
https://maven.apache.org/ref/3.3.3/maven-core/default-bindings.html
%MAVEN_HOME%/lib/maven-core-3.2.5/META-INF/plexus/default-bindings.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Mappings to default lifecycle, specific for each packaging. --> <component-set> <components> <!-- | POM |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>pom</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: pom-lifecycle --> <phases> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: pom-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | JAR |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>jar</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: jar-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-jar-plugin:2.4:jar </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: jar-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | EJB |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>ejb</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: ejb-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-ejb-plugin:2.3:ejb </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: ejb-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>ejb3</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: ejb3-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-ejb3-plugin:ejb3 </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: ejb3-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | MAVEN PLUGIN |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>maven-plugin</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: maven-plugin-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-classes> org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor </process-classes> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-jar-plugin:2.4:jar, org.apache.maven.plugins:maven-plugin-plugin:3.2:addPluginArtifactMetadata </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: maven-plugin-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | WAR |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>war</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: war-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-war-plugin:2.2:war </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: war-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | EAR |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>ear</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: ear-lifecycle --> <phases> <generate-resources> org.apache.maven.plugins:maven-ear-plugin:2.8:generate-application-xml </generate-resources> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources </process-resources> <package> org.apache.maven.plugins:maven-ear-plugin:2.8:ear </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: ear-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | RAR |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>rar</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: rar-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-rar-plugin:2.2:rar </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: rar-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> <!-- | PAR |--> <component> <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>par</role-hint> <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> <id>default</id> <!-- START SNIPPET: par-lifecycle --> <phases> <process-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:resources </process-resources> <compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:compile </compile> <process-test-resources> org.apache.maven.plugins:maven-resources-plugin:2.6:testResources </process-test-resources> <test-compile> org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile </test-compile> <test> org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test </test> <package> org.apache.maven.plugins:maven-par-plugin:par </package> <install> org.apache.maven.plugins:maven-install-plugin:2.4:install </install> <deploy> org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy </deploy> </phases> <!-- END SNIPPET: par-lifecycle --> </lifecycle> </lifecycles> </configuration> </component> </components> </component-set>
note:
phase 就是接口 (一个接口可以被不同的类实现(一个phase被不同的plugin绑定))
plugin 就是实现类 (一个类可以实现多个接口(一个plugin绑定到不同的phase))
note:
(Note: In Maven 2.0.5 and above, multiple goals bound to a phase are executed in the same order as they are declared in the POM, however multiple instances of the same plugin are not supported. Multiple instances of the same plugin are grouped to execute together and ordered in Maven 2.0.11 and above).
执行顺序确定性(先来后到)
note:
usage: mvn [options] [<goal(s)>] [<phase(s)>]
举例:
mvn -h
mvn compiler:compile
mvn compile
note:
goal(s) 是直接运行任务,是点
phase(s) 是在所属生命周期内扫描Bingdings至指定的阶段然后依次执行,是段
... g1 {...} g2 {...} g3 {...} ...
=============================>
注意:
mvn clean compile compile
上面这条命令没有错误,涉及到clean生命周期和default生命周期,但是在default生命周期中会依次扫描compile phase,但是重复执行看起来没有意义