美文网首页
Maven私有仓库——基于Nexus的搭建

Maven私有仓库——基于Nexus的搭建

作者: 落日清风 | 来源:发表于2017-11-28 14:39 被阅读0次

进入新公司搭建nexus私有maven仓库时,又发现一些细节很模糊了,so决定记录下来具体流程以便日后使用。

基于nexus-3.6.1-02版本

A.准备工作

1.压缩包内文件夹解压至同一目录,例如D:\Program\nexus
2.cmd进入nexus\nexus-3.6.0-02\bin目录下
3.输入nexus.exe /run即可在默认端口启动nexus(linux下为./nexus run &)&代表后台运行
4.如端口被占用等情况,可于Nexus\nexus-3.6.1-02\etc下修改nexus-default.properties改变端口

B.基础配置

1.默认最高权限账户:admin 密码:admin123
2.Blob Stores,如果没有自定义的话,默认地址为Nexus\sonatype-work\nexus3\blobs\default,如果需要可以自行创建新的仓储路径
3.Repositories,对应maven仓库,首先需要的是一个代理仓库,一般默认为官方中央仓库。国内的话,默认为aliyun的中央仓库即可。
4.如果存在第三方jar包,需要创建类型为hosted的repositories,用于mvn depoly发布,注意Deployment policy要设置为allow redeploy。

  1. 公司自有项目可建立对应的snapshot和releases仓库,Maven2下的version policy需设置为对应版本,仓库类型为hosted。方便起见可直接在项目pom文件内进行如下配置:
<distributionManagement>
    <snapshotRepository>
        <id>仓库ID</id>
        <name>仓库名称</name>
        <url>
            http://地址:端口/repository/仓库ID/
        </url>
    </snapshotRepository>
    <repository>
        <id>仓库ID</id>
        <name>仓库名称</name>
        <url>
            http://地址:端口/repository/仓库ID/
        </url>
    </repository>
</distributionManagement>
  1. 一般公司内部需要创建多个仓库,这时候就需要创建group类型的repositories用于统一访问多个仓库
  2. 配置私有仓库,在项目下的pom文件中加入
<repositories>
    <repository>
        <id>仓库ID</id>
        <name>仓库名称</name>
        <url>
            http://地址:端口/repository/仓库ID/
        </url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>

或者在本地maven的conf文件夹中,修改settings.xml加入镜像

<mirrors>
  <mirror>
    <id>仓库ID</id>
    <name>仓库名称</name>
    <url>
        http://地址:端口/repository/仓库ID/
    </url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

具体的mirroOf属性可参照http://blog.csdn.net/isea533/article/details/21560089
一般来说搭建公司私有仓库,配置为*,即所有请求均被私有仓库拦截即可,再在私有仓库中配置中央仓库的代理即可。

C.Nexus上传私有包

1.上传私有包时需要验证nexus的账号密码,一般配置于本地maven的settings.xml文件中。

<servers>
  <server>   
    <id>仓库ID</id>   
    <username>nexus username</username>
    <password>nexus password</password>   
  </server>
</servers>

2.idea中运行mvn clean deploy即可发布,成功后可于nexus仓库中搜索查看到。


常见问题

1.mvn deploy报错,报错信息中有如下:
RELEASE does not allow metadata in path
该问题是snapshots版本的jar包发布的仓库版本策略错误,在nexus中点击对应的仓库查看可发现Maven2-version policy的值为releases。目前不能修改版本策略,重建一个snapshots版本的仓库即可。


如存在问题欢迎指教!

相关文章

网友评论

      本文标题:Maven私有仓库——基于Nexus的搭建

      本文链接:https://www.haomeiwen.com/subject/guyhzttx.html