• Maven 私服 Nexus 的部署及项目应用


    Nexus 简介


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

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

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

    部署 Nexus


    使用 Docker Compose 编排部署应用容器。服务器地址:192.168.1.100

    创建 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://192.168.1.100:8081

    初始账号:admin

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

    file

    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://192.168.1.100/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://192.168.1.100/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    

    更新 Maven 配置,项目就可以从 Nexus 私服中拉取依赖了。

    同样,也可以将打包好的项目部署到 Nexus 私服中:

    $ mvn deploy
    

    更多干货请移步:https://antoniopeng.com

  • 相关阅读:
    Tampermonkey 油猴脚本开发 入门
    k8s 上安装 lamp 环境
    centOS 7.9 k8s 安装 和 基本命令
    力扣59-螺旋矩阵 II
    力扣54-螺旋矩阵
    力扣705-设计哈希集合
    力扣706-设计哈希映射
    scrapy参数-COOKIES_ENABLED
    优雅降级、渐进增强
    e-cahr的地图组件封装(浙江省为例)
  • 原文地址:https://www.cnblogs.com/antoniopeng/p/14370704.html
Copyright © 2020-2023  润新知