mirrors
用法为:
<mirrors>
<mirror>
<id>releases</id>
<url>http://47.104.176.200:8081/repository/maven-releases/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
mirrorOf的作用
镜像拦截器。对应的是repository的id。
多个镜像的生效地址:
mvn help-effective-settings -Daliyun=central
同样的道理,使用网易镜像,则执行:
mvn help:effective-settings -Dnetease=central
用法有四种:
# 拦截所有
* = everything
# 拦截不在本地,和不在文件的
external:* = everything not on the localhost and not file based.
# 拦截 repo或repo1
repo,repo1 = repo or repo1
# 拦截除了repo1
*,!repo1 = everything except repo1
central的作用
central(中央仓库)是默认的仓库,如果不配置任何仓库,那么就会去中央仓库下载,但是它比较慢。
如果我们想要快一些的镜像,那么就可以使用central
来拦截中央仓库,这样就不会到中央仓库下载了。
注: 多个mirror不会自动判断,如果找不到,就去下一个找。而是只有上一个mirror无法链接的时候,才会去下一个找。
mirrorOf * 好不好
很多人为了方便,这么写,其实并不好。
因为这样一个mirrorOf把所有仓库都拦截了。如果这个镜像没有,那么也不回去后面下载。
mirrorOf * 后面的仓库都不会生效么
这个不一定,虽然mirrorOf * 会拦截所有仓库,但是如果前面找不到,或者慢,还是会去后面找,可能造成不必要的错误,所以不要怕麻烦,用私服的时候把其他仓库都注释掉即可。
repositories标签的作用
用来配置maven项目的远程仓库。
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
pluginRepository
用来配置maven插件的远程仓库。
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
servers配置远程仓库认证信息
<!--配置远程仓库认证信息-->
<servers>
<server>
<id>bbsnexus</id>
<username>licui</username>
<password>a111111</password>
</server>
</servers>
distributionManagement配置上传jar包到远程仓库
<distributionManagement>
<repository>
<id>bbsnexus</id>
<name>bbsidrepository</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/bbsid</url>
</repository>
</distributionManagement>