maven学习巩固
1.认识Maven
2.特点
a)约定优于配置
b)简单
c)测试支持
d)构建简单
e)CI
f)插件丰富
3.下载
a)https://maven.apache.org/download.cgi
b)安装
c)maven-model-builder-3.3.9.jar/org/apache/maven/model
d)配置 MVM_HOME
i.Windows path
ii.Linux .bash_profile
iii.MAVEN_OPTS
iv.配置setting.xml
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>ui</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>osc</id>
<mirrorOf>central</mirrorOf>
<url>http://maven.oschina.net/content/groups/public/</url>
</mirror>
<mirror>
<id>osc_thirdparty</id>
<mirrorOf>thirdparty</mirrorOf>
<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
</mirror>
4.新建一个Maven项目
a)项目结构
b)pom.xml
i.groupId com.gupaoedu
ii.artfactId 功能命名
iii.version 版本号
iv.packaging 打包方式 默认是jar
v.dependencyManagement
1. 只能出现在父pom
2. 统一版本号
3. 声明 (子POM里用到再引)
vi.Dependency
1.Type 默认jar
2.scope
a)compile 编译 例如spring-core
b)test 测试
c)provided编译 例如 servlet
d)runtime运行时 例如JDBC驱动实现
e)system 本地一些jar 例如短信jar
f)依赖传递 第一列表示直接依赖的scope,第一行表示间接依赖的scope
| compile | test | provided | runtime | |
|---|---|---|---|---|
| compile | compile | - | - | runtime |
| test | test | - | - | test |
| provided | provided | - | provided | provided |
| runtime | runtime | - | - | runtime |
g)依赖仲裁
i.最短路径原则
ii.加载先后原则
h)exclusions
i.排除包
vii.生命周期 lifecycle/phase/goal
1.A Build Lifecycle is Made Up of Phases
2.A Build Phase is Made Up of Plugin Goals
5.版本管理
a)1.0-SNAPSHOT
i.repository 删除
ii.mvn clean package -U (强制拉一次)
b)主版本号.次版本号.增量版本号-<里程碑版本>
1.0.0-RELAESE
6.常用命令
a)compile
b)clean 删除target/
c)test test case junit/testNG
d)package 打包
e)install 把项目install到local repo
f) deploy 发本地jar发布到remote
7.插件
a)常用插件
i.https://maven.apache.org/plugins/
ii.http://www.mojohaus.org/plugins.html
iii.findbugs 静态代码检查
iv.versions 统一升级版本号
1.mvn versions:set -DnewVersion=1.1
v.source 打包源代码
vi.assembly 打包zip、war
vii.tomcat7
8.自定义插件 https://maven.apache.org/guides/plugin/guide-java-plugin-development.html
a)<packaging>maven-plugin</packaging>
b)extends AbstractMojo
c)
d)mvn install
e)参数传递
9.Profile
a)使用场景 dev/test/pro
b)setting.xml 家和公司两套
10.自定义插件
a)下载
b)安装 解压
c)使用http://books.sonatype.com/nexus-book/reference3/index.html
i.http://192.168.1.6:8081/nexus
ii.admin/admin123
d)发布
i.pom.xml 配置
1.
2.
e)下载jar配置
i.配置mirror
ii.Profile
11.自定义插件
a)生成一个archetype
i.mvn archetype:create-from-project
ii.cd /target/generated-sources/archetype
iii.mvn install
b)从archetype创建项目 mvn archetype:generate -DarchetypeCatalog=local