maven入门(1-3)maven的生命周期
- clean 清理项目
- default 构建项目
- site 建立项目站点
命令行与生命周期
- 命令行用于调用maven的生命周期阶段,如mvn clean、mvn test、mvn clean install、mvn clean deploy site-deploy
4.1)intro: maven-dependency-plugin有多个目标,每个目标对应一个功能,上述提到的几个功能分别对应的插件目标为 dependency:analyze, dependency:tree 和 dependency:list;4.2)这是一种通用的写法: 冒号前面是 插件前缀,后面是该插件的目标;(干货——引入了插件前缀)
A1)default 与插件目标的绑定关系是由 项目打包类型所决定的,打包类型是通过 POM 中的 packaging 元素定义的;A2)除了默认的 jar 打包类型外,常见的打包类型还有 war,pom,maven-plugin,ear等;
- D:\classical_books\java_set\maven_in_action\mycode\chapter3>mvn clean install
- [INFO] Scanning for projects...
- [WARNING]
- [WARNING] Some problems were encountered while building the effective model for com.maven.chapter3:service:jar:1.0-SNAPSHOT
- [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 22, column 15
- [WARNING]
- [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
- [WARNING]
- [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
- [WARNING]
- [INFO]
- [INFO] ------------------------------------------------------------------------
- [INFO] Building service says hello maven. 1.0-SNAPSHOT
- [INFO] ------------------------------------------------------------------------
- [INFO]
- [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ service ---
- [INFO] Deleting D:\classical_books\java_set\maven_in_action\mycode\chapter3\target
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] skip non existing resourceDirectory D:\classical_books\java_set\maven_in_action\mycode\chapter3\src\main\resources
- [INFO]
- [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
- [INFO] Changes detected - recompiling the module!
- [WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
- [INFO] Compiling 1 source file to D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\classes
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] skip non existing resourceDirectory D:\classical_books\java_set\maven_in_action\mycode\chapter3\src\test\resources
- [INFO]
- [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
- [INFO] Changes detected - recompiling the module!
- [WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
- [INFO] Compiling 1 source file to D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\test-classes
- [INFO]
- [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
- [INFO] Surefire report directory: D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\surefire-reports
- -------------------------------------------------------
- T E S T S
- -------------------------------------------------------
- Running com.maven.chapter3.service.HelloTest
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 sec
- Results :
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
- [INFO]
- [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
- [INFO] Building jar: D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT.jar
- [INFO]
- [INFO] --- maven-shade-plugin:1.2.1:shade (default) @ service ---
- [INFO] Replacing original artifact with shaded artifact.
- [INFO] Replacing D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT.jar with D:\classical_books\java_set\maven_in
- _action\mycode\chapter3\target\service-1.0-SNAPSHOT-shaded.jar
- [INFO]
- [INFO] --- maven-install-plugin:2.4:install (default-install) @ service ---
- [INFO] Installing D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT.jar to D:\classical_books\java_set\maven_in_
- action\local_repo\com\maven\chapter3\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
- [INFO] Installing D:\classical_books\java_set\maven_in_action\mycode\chapter3\pom.xml to D:\classical_books\java_set\maven_in_action\local_repo\com\ma
- ven\chapter3\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 8.305 s
- [INFO] Finished at: 2016-06-22T18:43:41+08:00
- [INFO] Final Memory: 17M/142M
- [INFO] ------------------------------------------------------------------------
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.1</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <phase>verify</phase>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
A1)executions 下每个execution 子元素可以用来配置执行一个任务;A2)该例中配置了一个id 为 attach-sources 的 任务,通过 phrase 配置,将其绑定到 verify 生命周期阶段上,再通过 goal 配置指定要执行的插件 目标,至此,自定义插件配置完成了;(干货——总结了自定义插件配置的steps)
- D:\classical_books\java_set\maven_in_action\mycode\chapter3>mvn verify
- [INFO] Scanning for projects...
- [WARNING]
- [WARNING] Some problems were encountered while building the effective model for com.maven.chapter3:service:jar:1.0-SNAPSHOT
- [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 22, column 15
- [WARNING]
- [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
- [WARNING]
- [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
- [WARNING]
- [INFO]
- [INFO] ------------------------------------------------------------------------
- [INFO] Building service says hello maven. 1.0-SNAPSHOT
- [INFO] ------------------------------------------------------------------------
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-source-plugin/2.1.1/maven-source-plugin-2.1.1.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-source-plugin/2.1.1/maven-source-plugin-2.1.1.pom (5 KB at 2.6 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/14/maven-plugins-14.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/14/maven-plugins-14.pom (13 KB at 32.4 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-source-plugin/2.1.1/maven-source-plugin-2.1.1.jar
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-source-plugin/2.1.1/maven-source-plugin-2.1.1.jar (24 KB at 59.4 KB/se
- c)
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] skip non existing resourceDirectory D:\classical_books\java_set\maven_in_action\mycode\chapter3\src\main\resources
- [INFO]
- [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
- [INFO] Nothing to compile - all classes are up to date
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] skip non existing resourceDirectory D:\classical_books\java_set\maven_in_action\mycode\chapter3\src\test\resources
- [INFO]
- [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
- [INFO] Nothing to compile - all classes are up to date
- [INFO]
- [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
- [INFO] Surefire report directory: D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\surefire-reports
- -------------------------------------------------------
- T E S T S
- -------------------------------------------------------
- Running com.maven.chapter3.service.HelloTest
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.056 sec
- Results :
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
- [INFO]
- [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
- [INFO] Building jar: D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT.jar
- [INFO]
- [INFO] --- maven-shade-plugin:1.2.1:shade (default) @ service ---
- [INFO] Replacing original artifact with shaded artifact.
- [INFO] Replacing D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT.jar with D:\classical_books\java_set\maven_in
- _action\mycode\chapter3\target\service-1.0-SNAPSHOT-shaded.jar
- [INFO]
- [INFO] --- maven-source-plugin:2.1.1:jar-no-fork (attach-sources) @ service --- // maven-source-plugin:jar-no-fork 会得以执行.
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.4/maven-archiver-2.4.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.4/maven-archiver-2.4.pom (4 KB at 9.1 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/10/maven-shared-components-10.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/10/maven-shared-components-10.pom (9 KB at 19.0 KB/se
- c)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/2.0/maven-artifact-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/2.0/maven-artifact-2.0.pom (723 B at 1.8 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0/maven-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0/maven-2.0.pom (9 KB at 21.5 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.0/maven-model-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.0/maven-model-2.0.pom (3 KB at 6.2 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2.0/maven-project-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2.0/maven-project-2.0.pom (2 KB at 4.1 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/2.0/maven-profile-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/2.0/maven-profile-2.0.pom (2 KB at 3.6 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact-manager/2.0/maven-artifact-manager-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact-manager/2.0/maven-artifact-manager-2.0.pom (2 KB at 3.6 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-repository-metadata/2.0/maven-repository-metadata-2.0.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-repository-metadata/2.0/maven-repository-metadata-2.0.pom (2 KB at 3.1 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-11/plexus-archiver-1.0-alpha-11.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-11/plexus-archiver-1.0-alpha-11.pom (2 KB at 4.5 KB/sec
- )
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.9/plexus-components-1.1.9.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.9/plexus-components-1.1.9.pom (3 KB at 6.3 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.10/plexus-1.0.10.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.10/plexus-1.0.10.pom (9 KB at 21.0 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-15/plexus-container-default-1.0-alpha-15.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-15/plexus-container-default-1.0-alpha-15.pom (
- 2 KB at 4.1 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.0-alpha-15/plexus-containers-1.0-alpha-15.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.0-alpha-15/plexus-containers-1.0-alpha-15.pom (2 KB at 4.9 KB
- /sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.9/plexus-1.0.9.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.9/plexus-1.0.9.pom (8 KB at 19.9 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-15/plexus-component-api-1.0-alpha-15.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-15/plexus-component-api-1.0-alpha-15.pom (948 B at
- 2.4 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/1.2-alpha-6/plexus-classworlds-1.2-alpha-6.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/1.2-alpha-6/plexus-classworlds-1.2-alpha-6.pom (3 KB at 6.1 KB
- /sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.3/plexus-utils-1.3.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.3/plexus-utils-1.3.pom (2 KB at 2.6 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-3/plexus-io-1.0-alpha-3.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-3/plexus-io-1.0-alpha-3.pom (2 KB at 3.7 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom (3 KB at
- 5.7 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.0-alpha-16/plexus-containers-1.0-alpha-16.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-containers/1.0-alpha-16/plexus-containers-1.0-alpha-16.pom (2 KB at 4.8 KB
- /sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/1.2-alpha-7/plexus-classworlds-1.2-alpha-7.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/1.2-alpha-7/plexus-classworlds-1.2-alpha-7.pom (3 KB at 6.1 KB
- /sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.4.9/plexus-utils-1.4.9.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.4.9/plexus-utils-1.4.9.pom (3 KB at 5.8 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.pom (3 KB at 7.1 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-9/plexus-archiver-1.0-alpha-9.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-9/plexus-archiver-1.0-alpha-9.pom (2 KB at 4.7 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-1/plexus-io-1.0-alpha-1.pom
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-1/plexus-io-1.0-alpha-1.pom (2 KB at 3.3 KB/sec)
- Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.4/maven-archiver-2.4.jar
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-9/plexus-archiver-1.0-alpha-9.jar
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-1/plexus-io-1.0-alpha-1.jar
- Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.jar
- Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.4/maven-archiver-2.4.jar (20 KB at 46.2 KB/sec)
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/1.0-alpha-1/plexus-io-1.0-alpha-1.jar (12 KB at 15.5 KB/sec)
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.jar (50 KB at 43.3 KB/sec)
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-9/plexus-archiver-1.0-alpha-9.jar (154 KB at 116.1 KB/s
- ec)
- Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar (262 KB at 95.3 KB/sec)
- [INFO] Building jar: D:\classical_books\java_set\maven_in_action\mycode\chapter3\target\service-1.0-SNAPSHOT-sources.jar // 生成了源码文件.
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 18.822 s
- [INFO] Finished at: 2016-06-22T19:00:32+08:00
- [INFO] Final Memory: 13M/171M
- [INFO] ------------------------------------------------------------------------
4.1)problem:当插件目标被绑定到不同的生命周期的时候,其执行顺序会由生命周期阶段的先后顺序决定;当多个目标被绑定到同一阶段时,他们的执行顺序会是怎样?4.2)solutions:当多个插件目标绑定到同一个阶段的时候,这些插件声明的先后顺序决定了目标的执行顺序;
1.1)problem:如何从命令行配置插件?1.2)solutions:用户可以在maven 命令中使用 -D 参数,并伴随一个参数键=参数值的形式,来配置插件目标的参数;参数-D 是java 自带的,其功能是通过命令行设置一个 java 系统属性;(干货——参数-D 是java 自带的,其功能是通过命令行设置一个 java 系统属性)
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <?xml version="1.0" encoding="UTF-8"?>
- <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.maven.chapter3</groupId>
- <artifactId>service</artifactId>
- <version>1.0-SNAPSHOT</version>
- <name>service says hello maven.</name>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.7</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>1.2.1</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>com.maven.chapter3.service.Hello</mainClass>
- </transformer>
- </transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.1</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <phase>verify</phase>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <version>1.3</version>
- <executions>
- <execution>
- <id>ant-validate</id>
- <phase>validate</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <echo>i am bound to validate phase.</echo>
- </tasks>
- </configuration>
- </execution>
- <execution>
- <id>ant-verify</id>
- <phase>verify</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <echo>i am bound to verify phase.</echo>
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </project>
A1)maven-antrun-plugin:run 与 validate 阶段绑定,从而构成了一个id为 ant-validate 的任务;A2)插件 全局配置中的 configuration 元素位于 plugin 元素下面,而这里的configuration元素则位于 execution 元素下,表示这是 特定任务的配置,而非插件整体的配置;A3)ant-validate任务配置了一个 echo 任务,而id为 ant-verify 任务也配置了一个 echo 任务;
2.1)看个荔枝: maven-compiler-plugin 的目标前缀是 compiler。2.2)在描述插件的时候,还可以省去版本信息,让 maven 自动获取最新版本来进行表述, 如: mvn help:describe-Dplugin=org.apache.maven.plugins:maven-compiler-plugin2.3)进一步简化:可以使用插件目标前缀来替换坐标: mvn help:describe-Dplugin=compiler2.4)想仅仅描述某个插件目标的信息,可以加上 goal 参数:
- mvn help:describe-Dplugin=compiler-Dgoal=compile
2.5)想让 maven-help-plugin 输出更详细的信息,可以加上 detail参数:
- mvn help:describe-Dplugin=compiler-Ddetail
- D:\classical_books\java_set\maven_in_action\mycode\chapter3>mvn -h
- usage: mvn [options] [<goal(s)>] [<phase(s)>]
- mvn help:describe-Dplugin=compiler
- mvn dependency:tree
4)problem+solutions:
4.1)problem:为什么不是 mavnen-dependency-plugin:tree 而是 dependency:tree ?4.2)solutions:可以尝试如下命令:
- mvn org.apache.maven.plugins:maven-help-plugin:2.1:describe-Dplugin=compiler
- mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:tree
4.2.1)上面的命令一对比,显然 前面的目录更加简洁,更容易使用;4.2.2)这也是 maven 引入 目标前缀的原因: help 是 maven-help-plugin 的目标前缀, 而 dependency 是 maven-dependency-plugin 的前缀,有了插件前缀,maven 就能够找到对应的 artifactId;不过 除了 artifactId ,maven 还需要得到 groupId 和 version 才能确定到 某个插件;
- <settings>
- <pluginGroups>
- <pluginGroup>com.your.plugins</pluginGroup>
- </pluginGroups>
- </settings>
对以上代码的分析(Analysis): maven 不仅仅会检查 org/apache/maven/plugins/maven-metadata.xml 和 org/codehaus/mojo/maven-metadata.xml ,还会检查 com/your/plugins/maven-metadata.xml;
A1)上述内容是从 中央仓库的 org.apche.maven.plugins groupId 下插件仓库元数据中截取的一些片段,从这段数据中就能看到 maven-clean-plugin 的前缀为 clean,maven-compile-plugin 的前缀为 compiler, maven-dependency-plugin 的前缀为 dependency;A2)当maven 解析到 dependency:tree 这样的命令后,他首先基于 默认的 groupId 归并所有插件仓库的元数据 org/apache/maven/plugins/maven-metadata.xml; 其次检查归并后的元数据, 找到对应的 artifactId 为 maven-dependency-plugin; 然后结合当前元数据的 groupId org.apache.maven.plugins;最后使用 章节8.3 的方法解析得到 version,从而得到完整的插件坐标;
maven入门(1-3)maven的生命周期的更多相关文章
- Maven系列第6篇:生命周期和插件详解,此篇看过之后在maven的理解上可以超越同级别90%的人!
maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第6篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...
- Maven详解(六)------ 生命周期
1.什么是 生命周期? Maven 强大的原因是有一个十分完善的生命周期,生命周期可以理解为项目构建步骤的集合,它定义了各个构建环节的执行顺序,有了这个顺序,Maven 就可以自动化的执行构建命令. ...
- Maven入门指南⑦:Maven的生命周期和插件
一个完整的项目构建过程通常包括清理.编译.测试.打包.集成测试.验证.部署等步骤,Maven从中抽取了一套完善的.易扩展的生命周期.Maven的生命周期是抽象的,其中的具体任务都交由插件来完成.Mav ...
- 《Maven实战》 第7章 生命周期与插件
7.1什么是生命周期 软件开发人员每天都在对项目进行清理.编译.测试及部署,Maven生命周期是对所有构建过程进行抽象和统一,含项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几 ...
- Maven核心概念之仓库,生命周期与插件
宏观图 一.仓库 统一存储全部Maven项目共享的构建的位置就是仓库. 仓库分为本地仓库和远程仓库.远程仓库又分为中央仓库(中央仓库是Maven核心自带的远程仓库),伺服(还有一种特殊的远程仓库,为节 ...
- Apache Maven(二):构建生命周期
Maven 约定的目录结构 我要遵循Maven已经约定好的目录结构,才能让maven在自动构建过程中找到对应的资源进行构建处理.以下是maven约定的目录结构: 项目名称 |-- pom.xml :M ...
- maven基础--下载安装配置命令生命周期
maven apache 公司开源项目,项目构建工具 好处: 项目小 坐标:公司名称+项目名称+版本信息 通过坐标去 仓库查找jar包 maven的两大核心: *赖管理:对jar包管理过程. 项目构建 ...
- HTTP协议 Servlet入门 Servlet工作原理和生命周期 Servlet细节 ServletConfig对象
1 HTTP协议特点 1)客户端->服务端(请求request)有三部份 a)请求行--请求行用于描述客户端的请求方式.请求的资源名称,以及使用的HTTP协议版本号 请求行中的GET ...
- Servlet第一篇【介绍Servlet、HTTP协议、WEB目录结构、编写入门Servlet程序、Servlet生命周期】
什么是Serlvet? Servlet其实就是一个遵循Servlet开发的java类.Serlvet是由服务器调用的,运行在服务器端. 为什么要用到Serlvet? 我们编写java程序想要在网上实现 ...
- Xamarin.Android 入门之:Android的生命周期
一.前言 活动是Android应用程序的基本构建块,他们可以在许多不同的状态存在.当你把一个Android程序置于后台,过一段时间再打开发现之前的数据还存在. 二.活动状态 下面的图表说明了一个活动可 ...
随机推荐
- PAT乙级-1043. 输出PATest(20)
给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一 ...
- 温故而知新--hashtable
哈希在实际使用中主要是当作私有内存,对数据进行插入和查找,哈希数据元素越多,操作的时候消耗的性能就越到,最明显的是当数据元素达到哈希的容量大小时,插入数据冲突概率会变大,并慢慢的退化为数组. 本例子中 ...
- 页面内部DIV让点击外部DIV 事件不发生(阻止冒泡事件)
如标题的情况,经常发生,尤其是在一些弹出框上面之类的. <script> function zuzhimaopao(){ e.stopPropagation(); } </scrip ...
- poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In t ...
- 15分钟理解HTTPS——通俗篇
| 导语 它很深奥吗?你肯定常常见过它,使用它,甚至离不开它... 它很浅显吗?你可能觉得看透它,理解它,甚至懂它... 让我们用15分钟,不那么学术地将它的深挖到底~ 什么?如何证明我是我?本文要上 ...
- 【django之权限组件】
一.需求分析 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,一个角色拥有若干权限.这样,就构造成& ...
- 《团队-Oldnote-最终程序》
托管平台地址:https://github.com/Vcandoit/Notepad 小组名称:TOP 小组成员合照:待添加 程序运行方法:手机app,安装到手机点击即可运行,打开页面会有图标提示. ...
- 课堂测试ch06
课堂测试ch06 下面代码中,对数组x填充后,采用直接映射高速缓存,所有对x和y引用的命中率为(D) A. 1 B. 1/4 C. 1/2 D. 3/4 解析:在填充了之后,对于x和y数组,只有在引用 ...
- Build to win--来自小黄衫
写在前面 首先非常荣幸.非常侥幸能以微弱的优势得到这次小黄衫,感谢各位老师同学的帮助,也谢谢来自<构建之法>团队的小黄衫赞助! 这次能够获得小黄衫,就像汪老师上课说的那样,其实,是一个积累 ...
- 201621123050 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...