Maven 简介
Apache Maven
Maven Users Centre
MVN Repository
Maven Central Repository
Available Plugins
常用命令
- mvn –version
- export MAVEN_OPTS=”-Xmx1024m -XX:MaxPermSize=128m”
- set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128m
- mvn help:system 环境变量和系统属性
- mvn help:effective-pom 查看有效POM文件
- mvn dependency:tree 查看依赖树
- mvn dependency:build-classpath 查看依赖CLASSPATH
- mvn dependency:resolve 下载依赖包
- mvn dependency:sources 下载依赖包源代码
Project Object Model
<project>
<parent>...</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>...</packaging>
<name>...</name>
<description>...</description>
<url>...</url>
<inceptionYear>...</inceptionYear>
<licenses>...</licenses>
<organization>...</organization>
<developers>...</developers>
<contributors>...</contributors>
<dependencies>...</dependencies>
<dependencyManagement>...</dependencyManagement>
<modules>...</modules>
<properties>...</properties>
<build>...</build>
<reporting>...</reporting>
<issueManagement>...</issueManagement>
<ciManagement>...</ciManagement>
<mailingLists>...</mailingLists>
<scm>...</scm>
<prerequisites>...</prerequisites>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<distributionManagement>...</distributionManagement>
<profiles>...</profiles>
</project>Super POM
MAVEN_HOME/lib/maven-model-builder-3.X.X.jar - org/apache/maven/model/pom-4.0.0.xml
代理设置
<proxy>
<id>internal_proxy</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>127.0.0.1</host>
<port>8087</port>
<nonProxyHosts>repo.halo9pan.cn|repo.hinkstack.info</nonProxyHosts>
</proxy>服务器认证
<server>
<id>central</id>
<username>your_username</username>
<password>your_password</password>
</server>Maven + SVN
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>cn.halo9pan</groupId>
<artifactId>hello-maven</artifactId>
<version>1.0.0</version>
<scm>
<connection>scm:svn:http://localhost/svn/nc</connection>
<developerConnection>scm:svn:https://localhost/svn/nc</developerConnection>
<url>
https://localhost/svn/nc
</url>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9</version>
<configuration>
<connectionType>
connection
</connectionType>
</configuration>
</plugin>
</plugins>
</build>
</project>- scm:add
- scm:bootstrap
- scm:branch
- scm:checkin
- scm:checkout
- scm:diff
- scm:edit
- scm:list
- scm:remove
- scm:status
- scm:tag
- scm:update
本地库
USER_HOME/.m2/repository
MAVEN_HOME/conf/settings:
镜像
<mirror>
<id>Central</id>
<url>http://repo1.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror><mirror>
<id>internal.mirror.halo9pan.cn</id>
<url>http://internal.mirror.halo9pan.cn/maven/</url>
<mirrorOf>*</mirrorOf>
</mirror>发布
<distributionManagement>
<repository>
<id>local-file-repository</id>
<name>Local File Repository</name>
<url>file:///home/halo9pan/maven/deploy</url>
</repository>
</distributionManagement>生命周期
MAVEN_HOME/lib/maven-core-3.2.3.jar - META-INF/plex/components.xml
mvn help:describe -Dcmd=deploy
Clean
pre-clean -> clean -> post-clean
Default
validate -> initialize -> generate-sources -> process-sources -> generate-resources -> process-resources -> compile -> process-classes -> generate-test-sources -> process-test-sources -> generate-test-resources -> process-test-resources -> test-compile -> process-test-classes -> test -> prepare-package -> package -> pre-integration-test -> integration-test -> post-integration-test -> verify -> install -> deploy
Site
pre-site -> site -> post-site -> site-deploy
阶段、目标
Packaging
process-resources – resources:resources
compile – compiler:compile
process-test-resources – resources:testResources
test-compile – compiler:testCompile
test – surefire:test
package – jar:jar
install – install:install
deploy – deploy:deploy