使用 Docker Compose 搭建 Nexus 依赖私服及使用配置

Nexus 简介

Nexus 是一个强大的依赖仓库管理器,极大地简化了内部仓库的维护和外部仓库的访问。

2016 年 4 月 6 日 Nexus 3.0 版本发布,相较 2.x 版本 有了很大的改变:

  • 对低层代码进行了大规模重构,提升性能,增加可扩展性以及改善用户体验。
  • 升级界面,极大的简化了用户界面的操作和管理
  • 提供新的安装包,让部署更加简单
  • 提供新的管理接口,以及增强对自动任务的管理

安装 Nexus

  • 创建 docker-compose.yml

    version: '3.1'
    services:
      nexus:
        restart: always
        image: sonatype/nexus3
        container_name: nexus
        ports:
          - 8081:8081
        volumes:
          - /usr/local/docker/nexus/data:/nexus-data
    
  • 启动容器

    $ docker-compose up -d
    

    启动时如果出现权限问题需要赋予数据卷目录可读可写的权限

    $ chmod 777 /usr/local/docker/nexus/data
    

登录访问 Nexus 页面

访问 http://{ip}:8081

  • 初始账号:admin
  • 初始密码在 /usr/local/docker/nexus/data/admin.password 文件中查看

image

Maven 配置 Nexus 认证信息

  • 修改 Maven 安装目录 conf 中的 settings.xml

  • servers 节点下配置 Nexus 私库的账号密码:

    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    

项目中配置 Nexus

  • 在 Maven 项目中的 pom.xml 配置 Nexus 代理仓库

    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://{host}:{port}/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Plugin Repository</name>
            <url>http://{host}:{port}/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    
  • 更新 Maven 配置,项目就可以从 Nexus 私服仓库拉取依赖了

从 Nexus 中拉取依赖

完成以上配置并刷新配置信息,即可从 Nexus 私库中拉取依赖

部署第三方依赖到 Nexus

mvn deploy

END

猜你喜欢

转载自www.cnblogs.com/antoniopeng/p/12687722.html