利用nexus构建maven、docker、npm、gradle私服仓库

前言

在小型公司发展历程中,开发对仓库的依赖不断提升,java web须要maven仓库、android须要gradle仓库、运维须要docker仓库…… 是时候搞一套仓库私服了。java

初识nexus

nexus是目前市场上,支持仓库种类最多,用户群体最大的一个仓库平台,上述全部的仓库,它均支持。
android

版本及支持的仓库
版本及支持的仓库

安装nexus

这里省略安装步骤,建议使用3.x及以上版本的nexusnginx

配置maven私服

这里仓库主要指2种,一种是代理的仓库,使得内网下载仓库没必要要去外网上下载,一种是私有的仓库,存公司内部jar。web

代理仓库

使用管理员账号(默认用户名admin 密码admin123 默认端口8080)
docker

建立仓库
建立仓库

点击建立仓库

选择maven2(proxy) 代理模式,这里填写阿里云的maven仓库代理,为了获得更快的下载速度。
maven.aliyun.com/nexus/conte…

私有仓库

选择host
选择host

建立私有仓库
建立私有仓库

上传本地jar


首先配置一下maven配置文件的用户名密码,我这里是/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/conf/settings.xml

<server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>复制代码

其次本地开发工具生成好jar,最后敲命令npm

mvn deploy:deploy-file 
  -DgroupId=com.***
  -DartifactId=***
  -Dversion=1.2.3 
  -Dpackaging=jar 
  -Dfile=D:\***-1.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/java/ 
  -DrepositoryId=nexus-releases复制代码

maven使用

修改pom文件,增长如下语句。json

<repositories>
        <repository>
            <id>nexus</id>
            <name>Maven Repository</name>
            <url>http://10.10.100.*:8081/repository/aliyun/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
       </repository>
    </repositories>复制代码

docker 代理


其中代理地址,我使用了阿里云的免费仓库代理地址。
私有仓库和上面java相似同理,能够本身操做下

docker使用

终端输入(这里我使用域名及端口映射出的docker仓库)bash

docker login -u admin -p admin123 rep.***.com:10055复制代码


当返回登陆成功时,说明配置正常。
而后,咱们尝试pull一个镜像

docker pull rep.*.com:10055/nginx复制代码


这里有个坑,咱们默认出去的多是http,而不少docker镜像默认拉取的是https,因此会报错,这里

vi /etc/docker/daemon.json
手动输入 { "insecure-registries":["rep.*.com:10055","10.10.100.11:8082"] }
systemctl daemon-reload
systemctl restart docker复制代码

上传镜像app

docker push rep.*.com:10055/<repo-name>:<tag>复制代码

npm仓库

建立npm仓库


镜像地址填写阿里的 npm.taobao.org/mirrors/npm…

使用

将npm注册表写入本地文件运维

npm config set registry http://localhost:8081/repository/npm/复制代码

或设置.npmrc 文件

registry = http://localhost:8081/repository/npm-all/复制代码

发布npm

npm publish --registry http://localhost:8081/repository/npm-internal/复制代码

android使用

gradle.properties配置基本信息

MAVEN_URL= http://localhost:8080/nexus/content/**
     MAVEN_SNAPSHOT_URL = http://localhost:8080/nexus/**
     #maven groupId
     GROUP=*
     #帐号
     NEXUS_USERNAME=admin
     #密码
     NEXUS_PASSWORD=admin123
     # groupid(最终你引用时的名字)
     GROUP_ID = com.*.tools 
     # type
     TYPE = aar
     # description
     DESCRIPTION = dependences lib复制代码

在Module的build.gradle配置Task

uploadArchives {
         configuration = configurations.archives
         repositories {
             mavenDeployer {
                 snapshotRepository(url: MAVEN_SNAPSHOT_URL) {
                     authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
                 }
                 repository(url: MAVEN_URL) {
                     authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
                 }
                 pom.project {
                    #版本,有更新时修改版本号,在上传
                     version '1.*.*'
                     #名字
                     artifactId '**'
                     groupId **
                     packaging TYPE
                     description '***'
                 }
             }
         }
     }

     artifacts {
        #编译的源码类型
         archives file('***.aar')
     }复制代码

引用的话,只须要在 project 的 build.gradle中配置

allprojects {
         repositories {
             jcenter()
             maven { url MAVEN_URL }
         }
     }复制代码

而后正常使用

compile 'com.**.tools:**:1.0.0'复制代码

结尾

有的以上仓库,能够知足绝大部分场景的需求,固然nexus仓库功能足够强大,你们能够对着本身场景研究。

相关文章
相关标签/搜索