1、安裝maven
yum install maven
2、修改目錄 /usr/share/maven/conf 下的配置,使用阿里雲鏡像加速
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
3、安裝 Nexus ( Installing Sonatype Nexus Repository OSS on CentOS 7)
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
解壓:
tar -xvzf latest-unix.tar.gz
解壓后出現兩個文件夾
latest-unix 主要用到這個文件夾
sonatype-work 保存所有配置文件的信息(不用動)
啟動nexus
進入 cd latest-unix/bin
./nexus start
如果啟動報錯
**************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
原因:當前是root用戶,需要配置一下:
進入 cd latest-unix/bin
vim nexus
命令模式下搜索(按 /查找) RUN
把#RUN_AS_USER= 改成RUN_AS_USER=root
啟動成功
**************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.
Public Repositories 對應的地址 http://IP地址:8081/nexus/content/groups/public/ 我們的倉庫地址
默認的用戶名和密碼時 admin:admin123
4、修改本地開發環境maven setting.xml 配置
在<mirros>標簽中添加:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>nexus maven</name>
<!--<url>http://xiaoshang.ydcfo.com:8081/repository/maven-public/</url>-->
<url>http://your ip:8081/nexus/content/groups/public/</url>
</mirror>
在<servers>標簽中添加:
<server>
<id>nexus-ne</id>
<username>yungui.zheng</username>
<password>nx-engine2018</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
5、在POM中添加發布地址
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http:/ip:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://ip:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
6、在IDEA下的LifeCycle下面點擊deploy發布到倉庫
7、查看發布的jar,搜索就可以看到依賴坐標

參考:
https://www.fosslinux.com/27838/installing-sonatype-nexus-repository-oss-on-centos-7.htm
https://blog.csdn.net/weixin_42719412/article/details/100672794
