在前面進行maven項目的構建中,可以看到在構建的過程中需要安裝maven的依賴插件
而在maven的默認配置中是在官網的中央倉庫和第三方的maven倉庫進行下載,速度偏慢。這裡提供阿里雲的maven插件庫(http://maven.aliyun.com/nexus/#view-repositories),可以在/data/apache-maven-3.5.2/conf/settings.xml 配置文件中進行修改。
在日常的開發構建中,我們也可以自己搭建一個私有的nexus。那麼什麼是nexus呢?
Nexus是maven的私有倉庫;
如果沒有nexus,項目的打包都需要在公網下載,不利於包的管理和共用;
如果沒有私有倉庫,我們所需要的所有構件都需要通過maven的中央倉庫和第三方的maven倉庫下載到本地,而一個團隊的所有人都需要重複地從maven倉庫中下載構件。
- 2、Nexus的安裝
<code>(1)下載Nexus
[root@linux-node2 ~]# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.5-02-bundle.tar.gz
--2017-12-25 10:45:42-- https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.5-02-bundle.tar.gz
Resolving sonatype-download.global.ssl.fastly.net (sonatype-download.global.ssl.fastly.net)... 151.101.228.249
Connecting to sonatype-download.global.ssl.fastly.net (sonatype-download.global.ssl.fastly.net)|151.101.228.249|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 73187012 (70M) [application/octet-stream]
Saving to: ‘nexus-2.14.5-02-bundle.tar.gz’
5% [=======> ] 4,375,805 76.4KB/s eta 12m 59s
(2)解壓Nexus
[root@linux-node2 ~]# tar -zxvf nexus-2.14.5-02-bundle.tar.gz
[root@linux-node2 ~]# mv nexus-2.14.5-02 sonatype-work /data/
(3)啟動Nexus
[root@linux-node2 ~]# cd /data/nexus-2.14.5-02
[root@linux-node2 nexus-2.14.5-02]# ls
bin conf lib LICENSE.txt logs nexus NOTICE.txt tmp
[root@linux-node2 nexus-2.14.5-02]# cd bin/
[root@linux-node2 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/>[root@linux-node2 bin]# export RUN_AS_USER=root
[root@linux-node2 bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
[root@linux-node2 bin]# netstat -tulnp |grep 8081
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 4773/java
(4)瀏覽器訪問倉庫
瀏覽器訪問:http://192.168.56.12:8081/nexus,如圖:/<code>
點擊右上角"login" 默認用戶名密碼:admin ,admin123
在倉庫中,默認會在本地去查找插件,當未發現有插件時,會通過第三方倉庫查到,這些倉庫的類型都是hosts類型,也就是在本機進行查詢。
當本地內未能查找到相應的插件,會通過代理(proxy)類型進行下載插件,配置就在Central——>Remote Storage Location(回源地址),這裡我們填寫阿里雲的maven遠程倉庫進行下載
http://maven.aliyun.com/nexus/content/groups/public/
配置完成nexus後,在修改maven的settings配置
<code>[root@linux-node2 ~]# vim /data/apache-maven-3.5.2/conf/settings.xml
將其中的倉庫鏈接地址修改為:
http://192.168.56.12:8081/nexus/content/groups/public//<code>
這樣在構建時,首次會從阿里雲的maven倉庫中下載插件,後面再次重新下載插件時會從本地進行下載
閱讀更多 菠蘿愛吃鳳梨 的文章