使用nexus搭建内网maven镜像

背景:

内网环境,使用maven构建管理项目只能自己搭建镜像。nexus3.x需联网使用,所以选用nexus2.x来搭建镜像

环境:

1、nexus-professional-2.14.10

2、maven3.5.2

3、windows10

步骤:

  • 搭建nexus环境

1、将下载好的nexus-professional-2.14.10解压至任意目录。

2、打开刚才解压的目录,首先进入config目录,修改nexus.properties,修改默认端口号。

#修改端口号
application-port=12345
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

# orientdb buffer size in megabytes
storage.diskCache.bufferSize=4096

打开cmd,进入nexus的bin目录,执行

 nexus install

运行完成后,会生成windows服务,可以在windows服务列表里看到,默认是自动启动。
3、nexus启动后,会在sonatype-work/nexus/下面生成一批目录,其中storage/thirdparty目录就是存放各种依赖的目录。
4、将我们外网电脑在maven中下载好的repository复制到sonatype-work/nexus/storage/thirdparty中,重启nexus服务。本地maven仓库地址一般会在C:\Users\your user\.m2\repository
5、访问http://127.0.0.1:12345/nexus就能看到内网镜像的仓库了。其中Repository Path 就是本地的镜像地址,后面会用到。

本地镜像仓库

  • 配置maven
    1、修改MAVEN_HOME/config/settings.xml,增加以下节点

    
      localRep
      central
      the Mirror for neiwang
      http://your ip:12345/nexus/content/groups/public/

    
    
  

2、更新IDE的maven配置,这里以eclipse为例。打开eclipse-window-Preferences-Maven-User Settings,选择Global Settings,选择maven安装目录下conf目录中的settings.xml,选择完毕后,点击Update Settings 。


eclipse配置maven

3、更新你的maven项目。

结束:

后续更新依赖的时候,只需把外网的repository复制到nexus的sonatype-work/nexus/storage/thirdparty中即可。

你可能感兴趣的:(使用nexus搭建内网maven镜像)