任何一个构件(jar包) 都有一个惟一的GAV坐标,根据这个坐标,能够定位到它在仓库的存储路劲。编程
以 junit为例子缓存
<groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version>\junit\junit\4.12\junit-4.12.jar安全
若是有identifier,或者 extension 或在jar包名字后面加对应的名字服务器
{artificat}-{version}-{identifier}.{packing}网络
对于Maven来讲,仓库有两种,本地仓库和远程仓库。maven
maven在构建的时候,会优先从本地仓库找,若是没有再去远程仓库找而且下载到本地仓库。ide
本地仓库 默认是在 ~/.m2/repository 下面, 也能够自定义。经过修改maven的配置文件 MAVEN_HONE/conf/Setting.xml布局
推荐在~/.m2/setting.xml 下作修改, 若是没有则拷贝MAVEN_HONE/conf/Setting.xml一份过来,由于conf/Setting.xml是全局的配置。post
远程仓库是一个在线的MAVEN仓库,能够分为三类, 中央仓库,私服,其余类型网站
能够说是一个默认的 公共的远程仓库, 无论怎么说,maven至少有一个远程可用的仓库存在,以保证在构建的时候,本地仓库没有任何可用的jar时候能够访问远程库进行下载。
无需作任何配置的状况下, Maven默认将中央库配置http://repo1.maven.org/maven2 下面。
私服是一个特殊的远程仓库,或者说是自行搭建的一个局域网内的在线仓库,若是是公网那就编程中央仓库了,
在有私服的状况下,在本地库不存在须要的jar 时候,会去私服上找,若是私服没有再去中央库下载。因此 私服它缓存了各大中央仓库的构建,另外私服也能够管理自行编写的构件。
针对有网略限制,或者有安全策略的(毕竟开源的jar并非100%可靠的)社区或企业来讲,搭建私服是一个很好的管理手段。
私服具备一下优点:
1. 节省外网带宽。 2.加速构建,毕竟是局域网内 3. 上传自定义构建 4.加强构建管理,5下降中央仓库的负荷
仓库配置,能够在全局的配置文件或者项目pom文件里面 作配置.
配置节点是 <repositoires>和<pluginRepositories>
分别对应 构件库和插件库,虽然理论上都是jar,根据做用不一样作了配置区分。
另外配置的时候能够指定下载 release仍是snapshot
id,name,和url 能够任务是仓库的GAV坐标。
<repositories> <repository> <id>jboss</id> <name>jboss</name> <url>http://repostiory.jboss.com/maven2</url> <releases> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> <updatePolicy>daily</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> <updatePolicy>daily</updatePolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>jboss</id> <name>jboss</name> <url>http://repostiory.jboss.com/maven2</url> <releases> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> <updatePolicy>daily</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> <updatePolicy>daily</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories>
下载策略指的是,什么时候去中央库缓存,同步,更新jar包。能够配置的值有
daily; 天天同步一次
never: 历来不一样步
always:每次构建的时候 都去中央库同步一次
interval X: x表示每隔多少分钟同步跟新一次
检验策略指的是,在同步或者上传构件的同时,会生成一份校验和文件,当maven客户端去下载构件的时候会进行校验,配置的策略作出不一样的处理。
可配置的值有
warn: 发出警告,但依然会继续构建
ignore: 忽略校验信息
fail: 构建失败
大部分远程仓库是不须要认证,直接能够访问。 出于安全考虑远程仓库提供了认证服务。
与仓库配置不一样的是,它只能配置在 setting.xml里面
配置节点是<servers>,同时支持2种认证方式, 用户名密码和非对称密钥。
<servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> </servers>
mvn clean deploy 中的deploy阶段 并不是把jar或者war 部署到应用服务器上,对于初学者来讲很是容易混淆,这里的deploy是将构件 发不到远程仓库,至于发布到哪一个远程仓库,须要早配置文件里面作配置,
配置节点是< distributionManagement>,id,name,url 是标识,能够经过id 在setting里面配置对应的认证策略。
能够配置 release repository 和snapshot repostiory
<distributionManagement> <repository> <id>ditritbution</id> <name>repository name</name> <url>url here</url> </repository> <snapshotRepository> <id> snapshot distribtion id</id> <name>repository name</name> <url>url here</url> </snapshotRepository> </distributionManagement>
若是X仓库提供了Y仓库的全部内容,则X仓库是Y仓库的镜像,换句话说,从Y仓库得到的构建,也能从X仓库得到,因为网络缘由或者防火墙的缘故,各区域或就进建一个镜像,按期同步源库的构建,就近原则,因此镜像的效率每每要高于源库。
镜像的配置在 setting.xml里面,配置节点是< mirrors>, 其中mirrorOf 表示一个中央仓库的ID,任何一个访问这个Id的请求都会路由到这个镜像。
其中 mirrorOf 支持通配
如
<mirrorOf>*</mirrotOf> 匹配全部远程仓库
<mirrorOf>repo1,repor2</mirrotOf>匹配repo1,repo2远程仓库
<mirrorOf>*,! repor2</mirrotOf>匹配全部远程仓库 repo2除外
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> </mirrors>
在平常开发中,想要具体知道 构建的GAV,能够经过如下几个搜索网站进行查询
Sonatype Nexus:https://repository.sonatype.org/ MVNBrowser: http://www.mvnbrowser.com Mvn Repository: http://mvnrepository.com