一、nexus工作原理图
私服搭建,可以参考下面链接:
搭建Maven私服Nexus3_石工记的博客-CSDN博客
二、项目配置注意事项(两个配置)
1.maven中settings的两个配置:添加<server/>(不必需项)和<mirror/>(必需项)
1.1 settings中<server/>配置
<server>
<id>nexus<id/>
<username>admin</username>
<password>admin<password/>
<server/>
1.2 settings中<mirror/>配置
<mirror>
<id>nexus-releases</id>
<name>nexus-releases</name>
<url>https://127.0.0.1:8081/repository/maven-releases/</url>
<mirrorOf>central</mirrorOf>
</mirror>
2.项目的pom.xml配置<distributionManagement/>
2.1 settings配置<server/><mirror>(如果上述配置,此项可以略过)
<server>
<id>nexus<id/>
<username>admin</username>
<password>admin<password/>
<server/>
<mirror>
<id>nexus-releases</id>
<name>nexus-releases</name>
<url>https://127.0.0.1:8081/repository/maven-releases/</url>
<mirrorOf>central</mirrorOf>
</mirror>
2.2 <distributionManagement/>,项目打包上传到私服(必配置)
2.2.1配置前置
在nexus中的maven-releaser中hosted选项配置为Allow redeply,如下图
2.2.2当项目打包部署到nexus时,配置pom.xml中<distributionManagement/>选项,选项中添加nexus中的id、name、url,其中<distributionManagement/>中<repository/>的id必项与settings.xml中<server/>是ID相同,否则会失败,包上传不到私服中
<repository> <id>nexus</id> <name>Release Repository</name> <url>https://127.0.0.1:8081/repository/maven-releases/</url> </repository>