在前面进行maven项目的构建中,能够看到在构建的过程当中须要安装maven的依赖插件,如图:image.pngjava

而在maven的默认配置中是在官网的中央仓库和第三方的maven仓库进行下载,速度偏慢。这里提供阿里云的maven插件库(http://maven.aliyun.com/nexus/#view-repositories),能够在/data/apache-maven-3.5.2/conf/settings.xml 配置文件中进行修改。node

 

在平常的开发构建中,咱们也能够本身搭建一个私有的nexus。那么什么是nexus呢?linux

Nexus是maven的私有仓库;apache

若是没有nexus,项目的打包都须要在公网下载,不利于包的管理和共用;vim

若是没有私有仓库,咱们所须要的全部构件都须要经过maven的中央仓库和第三方的maven仓库下载到本地,而一个团队的全部人都须要重复地从maven仓库中下载构件。浏览器

  • 二、Nexus的安装

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 script.
[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,如图:

点击右上角"login" 默认用户名密码:admin ,admin123app

在仓库中,默认会在本地去查找插件,当未发现有插件时,会经过第三方仓库查到,这些仓库的类型都是hosts类型,也就是在本机进行查询。maven

当本地内未能查找到相应的插件,会经过代理(proxy)类型进行下载插件,配置就在Central——>Remote Storage    Location(回源地址),这里咱们填写阿里云的maven远程仓库进行下载tcp

http://maven.aliyun.com/nexus/content/groups/public/ide

配置完成nexus后,在修改maven的settings配置

[root@linux-node2 ~]# vim /data/apache-maven-3.5.2/conf/settings.xml 
将其中的仓库连接地址修改成:
http://192.168.56.12:8081/nexus/content/groups/public/

这样在构建时,首次会从阿里云的maven仓库中下载插件,后面再次从新下载插件时会从本地进行下载