Nexus之自己搭建一个Maven私服

Maven公服 http://maven.aliyun.com

  1. https://hub.docker.com 搜索nexus

  2. docker pull sonatype/nexus3

  3. 创建Docker目录,创建nexus目录

    cd /usr/local/
    mkdir docker
    cd docker/
    mkdir nexus
    cd nexus/
    vi docker-compose.yml

  4. 使用Docker来安装和运行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

  5. docker-compose up -d

  6. 访问http://ip:8081

  7. 看日志
    docker ps
    docker logs containerID

  8. 如果报错没权限 查看data中是否有数据,让data有所有权限
    cd /data/

    ll

    docker-compose down

    chmod 777 data/

  9. docker-compose -up -d

  10. 启动nexus耗内存,看内存状态,nexus的启动需要耗费近1G内存;

    free -h

    htop

  11. 登陆nexus,默认用户名admin密码admin123

  12. 在Maven setting.xml中添加Nexus认证信息(servers节点下)


    nexus-releases
    admin
    admin123


    nexus-snapshots
    admin
    admin123

  13. 把项目和私服关联起来,在pom.xml添加配置


    nexus-releases
    Nexus Release Repository
    http://192.168.0.148:8081/repository/maven-releases/



    nexus-snapshots
    Nexus Snapshot Repository
    http://192.168.0.148:8081/repository/maven-snapshots/


注:ID与setting.xml中Servers配置的一致
url地址与私服仓库地址一致

  1. mvn deploy -Dmaven.test.skip=true

  2. 项目需要依赖先去本地找,本地没有去私服(内网)找,私服没有去官服找;
    第三方依赖或者自己写的jar,可以手动上传到私服,3.13版本nexus支持上传功能

  3. 配置代理仓库,目的是使项目走私服下载依赖到本地仓库


    nexus
    Nexus Repository
    http://192.168.0.148:8081/repository/maven-public/

    true


    true





    nexus
    Nexus Repository
    http://192.168.0.148:8081/repository/maven-public/

    true


    true


  4. 到这里项目就可以从私服到本地仓库了

1、SNAPSHOT版本代表不稳定(快照版本),还在处于开发阶段,随时都会有变化。当上传同样的版本号jar包的时候,SNAPSHOT会在版本号的后面自动追加一串新的数字,即日志标签;

2、RELEASE则代表稳定的版本(发布版本),一般上线后都会改用RELEASE版本。

在maven的依赖管理机制中,唯一标识一个依赖项是由该依赖项的三个属性构成的,分别是groupId、artifactId以及Version。这三个属性唯一确定一个组件(即我们平时说的war包和jar包)。

  1. 仓库中public是集合了快照版和发行版的映射

猜你喜欢

转载自www.cnblogs.com/cgy-home/p/11238128.html
今日推荐