---
title: "MAVEN专题"
author: "hxl1988_0311"
date: "2014-10-27T23:26:41Z"
tags: []
categories: ["研发管理"]
slug: "maven"
draft: false
lastmod: "2014-11-04T22:52:39Z"
id: 2148571
url: "https://sosop.iteye.com/blog/2148571"
---

一、maven中的依赖

1.除了坐标元素外，还有以下元素

type: 类型jar war

scope: 依赖范围    compile编译、测试、运行（默认）  test（测试）   provided（编译、测试）  runtime（测试、运行）system  import

optional：依赖是否可选 true 依赖此项目的项目不会依赖声明为true的项目

exclutions：排除依赖

 

2.依赖原则

最短路径和第一声明优先

 

3.排除依赖&lt;exclutions&gt;

    &lt;exclution&gt;

        &lt;groupId&gt;...

        &lt;artifactId&gt;...

    &lt;/exclution&gt;

&lt;/exclutions&gt;

 

4.归类依赖

&lt;properties&gt;

    &lt;xxx.verion&gt;&lt;/xxx.version&gt;

&lt;/properties&gt;

 

5.优化依赖

mvn dependency:list

mvn dependency:tree

mvn dependence:analyze

 

 

二、仓库

1.本地仓库

~/.m2/repository

在settings.xml中重新配置

 

2.中央仓库

3.私服

 

4.配置远程仓库&lt;repostiries&gt;

    &lt;repository&gt;

         &lt;id&gt;

         &lt;name&gt;

         &lt;url&gt;

         &lt;release&gt;true

         &lt;snapshots&gt;false

         &lt;layout&gt;default

 

5.认证

&lt;servers&gt;

    &lt;server&gt;

        &lt;id&gt;

        &lt;username&gt;

        &lt;password&gt;

 

6.部署至远程仓库

&lt;distributionManagement&gt;

    &lt;repository&gt;

        &lt;id&gt;

        &lt;name&gt;

        &lt;url&gt;

    &lt;snapshotRepository&gt;

         &lt;id&gt;

        &lt;name&gt;

        &lt;url&gt;

 

三、聚合和继承

1.聚合

&lt;package&gt;pom&lt;/package&gt;

&lt;modules&gt;

    &lt;module&gt;&lt;/module&gt;

&lt;/modules&gt;

2.继承

可继承的pom

**groupId  version**  decription  organization  inceptionYear  **url**  developers  **distributionManagement**  issueManagement  ciManagement  scm  properties  **dependencies dependencyManagement**  **repositories**

build  reporting

3.裁剪反应堆

mvn clean install -pl | -am | -amd | -rf