一、准備工作
二、安裝Nexus
1.解壓nexus文件
[root@centos6 var]# tar -zvxf nexus-2.12.0-01-bundle.tar.gz

nexus-2.12.0-01: 是nexus的核心文件
sonatype-work :maven下載jar存放地址
2.啟動Nexus
[root@centos6 nexus-2.12.0-01]# ./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用戶運行Nexus,可以修改bin/nexus中的配置跳過警告(修改RUN_AS_USER=root)
[root@centos6 nexus-2.12.0-01]# vi bin/nexus

重新啟動Nexus
[root@centos6 nexus-2.12.0-01]# ./bin/nexus start - **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.
注:Nexus默認端口8081,如果想修改端口。修改/conf/nexus.properties文件

訪問網址:http://192.168.1.11:8081/nexus/#welcome

點擊右上角的 Log In 按鈕即可登陸了。默認登錄賬號/密碼為: admin/admin123 ,登陸成功后的界面

點擊Repositories,將列表中所有Type為proxy 的項目的 Configuration 中的 Download Remote Indexes 設置為True

將Releases倉庫的Deployment Policy設置為 Allow ReDeploy

填寫完必選字段,點擊Upload Artifact(s)按鈕即可。
3.配置本地項目引用私服
自動發布構件到遠程倉庫,在工程pom.xml中添加
<distributionManagement>
<repository>
<id>releases</id><!--這個ID需要與你的release倉庫的Repository ID一致-->
<url>http://192.168.1.11:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id><!--這個ID需要與你的snapshots倉庫的Repository ID一致-->
<url>http://192.168.1.11:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
修改本地$MAVEN_HOME\conf目錄下的settings.xml配置文件,添加如下配置
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
在本地工程目錄下執行:
mvn deploy
所部署的包就自動上傳到了nexus安裝目錄下的

4.配置Maven從Nexus下載構件
在POM中配置Nexus私服,這樣的配置只對當前的Maven項目有效。
<!--指定Nexus的構件倉庫-->
<repositories>
<repository>
<id>public</id>
<name>Team Maven Repository</name>
<url>http://192.168.1.11:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!--指定Nexus的插件倉庫-->
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Team Maven Repository</name>
<url>http://192.168.1.11:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
在settings.xml中配置profile元素,這樣就能讓本機所有的Maven項目都使用自己的Maven私服。
<properties>
<repository>
<id>public</id>
<name>Team Maven Repository</name>
<url>http://192.168.1.11:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</properties>
