简介

  1. 私服不是Maven的核心概念,它仅仅是一种衍生出来的特殊的Maven仓库。通过建立自己的私服,就可以降低中央仓库负荷、节省外网带宽、加速Maven构建、自己部署构建等,从而高效地使用Maven。Nexus也是当前最流行的Maven仓库管理软件。

要求

  1. vps一台
  2. 系统centos7
  3. 内存大于1g

安装

  1. 这里我们使用docker进行安装,crt连接到vps

  2. yum -y install docker

    maven私服 nexus 的安装与使用-LMLPHP

  3. 启动docker: service docker start

  4. 查找nexus镜像 : docker search nexus

    maven私服 nexus 的安装与使用-LMLPHP

  5. 一般情况下,我们都是用stars最高的。docker pull docker.io/sonatype/nexus

  6. 启动nexus容器,对于以后的容器启动,[不清楚如何启动可以去docker hub 查看][https://hub.docker.com/],

    maven私服 nexus 的安装与使用-LMLPHP

  7. 一般直接搜索run 就可以找到如何启动

    maven私服 nexus 的安装与使用-LMLPHP

  8. 访问查看,管理员账户密码 admin admin123

    maven私服 nexus 的安装与使用-LMLPHP

  9. maven设置

    • setting.xml设置

      maven私服 nexus 的安装与使用-LMLPHP

    • pom文件设置

      maven私服 nexus 的安装与使用-LMLPHP

      <repositories>
      <repository>
      <id>nexus</id>
      <name>Team Nexus Repository</name>
      <url>http://nexus.jetbrains.org.cn/nexus/content/groups/public</url>
      <snapshots>
      <enabled>true</enabled>
      <updatePolicy>always</updatePolicy>
      </snapshots>
      </repository>
      </repositories>
      <pluginRepositories>
      <pluginRepository>
      <id>nexus</id>
      <name>Team Nexus Repository</name>
      <url>http://nexus.jetbrains.org.cn/nexus/content/groups/public</url>
      <snapshots>
      <enabled>true</enabled>
      <updatePolicy>always</updatePolicy>
      </snapshots>
      </pluginRepository>
      </pluginRepositories>

      maven私服 nexus 的安装与使用-LMLPHP

        <distributionManagement>
      <repository>
      <id>releases</id>
      <name>Nexus Release Repository</name>
      <url>http://nexus.jetbrains.org.cn/nexus/content/repositories/releases/</url>
      </repository>
      <snapshotRepository>
      <id>snapshots</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://nexus.jetbrains.org.cn/nexus/content/repositories/snapshots/</url>
      </snapshotRepository>
      </distributionManagement>

    备注: pom中上传的设置id要与maven setting中的id保持一致。

  10. 项目执行mvn delepoy 即可上传到私服。

  11. 至于releases库与snaoshots库的区别

    • 简单去说就是relesses库是稳定版本或者生产版本,snaoshots库是不稳定版本或开发版本,项目版本号后面带

      -SNAPSHOT 的都会上传到snaoshots库。

备注

如果觉得中央仓库慢的话,可以用我的私服 只需要配置 repositories 标签中的内容,下载 依赖, distributionManagement 标签中的内容为 上传, 无需配置,也不对外开放上传权限。

**如希望了解更多,请关注微信公众号**
![](https://img2018.cnblogs.com/blog/1821244/201910/1821244-20191006100212754-851343010.jpg)

05-07 15:11