本地仓库
Maven 的本地仓库,在第一次执行 maven 命令的时候被创建。本地仓库位置通过localRepository设置:
<localRepository>C:/apache-maven-3.2.5/repository</localRepository>
远程仓库
远程仓库包括中央仓库、私服、其他仓库。
中央仓库
Maven 中央仓库是由 Maven 社区提供的仓库,其中包含了大量常用的库,无需显示的配置就可以使用。在\lib\maven-model-builder-3.2.5.jar\org\apache\maven\model\pom-4.0.0.xml文件中,可以看到中央仓库的配置。
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
私服
私服是一种特殊的远程仓库,一般用来管理公司内部开发出来的 jar 包,这些 jar 包一般是公共类库,提供通用的功能,或者提供给其他项目依赖使用,把这些 jar 包上传到私服,其他项目中通过配置依赖就可以在项目中下载和使用到这些 jar 包提供的功能。在 setting 文件中配置私服:
<profiles>
<profile>
<id>nexus-repo</id>
<repositories>
<repository>
<id>nexus-public</id>
<url>http://localhost:8080/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-repo</activeProfile>
</activeProfiles>
需要注意激活 profile 配置就可以正常从私服下载jar包了。
搜索顺序
- 在本地仓库中寻找,如果没有则进入下一步。
- 在全局配置的私服仓库(在 settings.xml 中配置并激活)中寻找,如果没有则进入下一步。
- 在项目自身配置的私服仓库(pom.xml)中寻找,如果没有则进入下一步。
- 在中央仓库中寻找,如果没有则终止寻找。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。