linux下nexus企业maven私有仓库的搭建和使用——<02>


提示:以下是本篇文章正文内容,下面案例可供参考

一、基本理解和介绍

1.1 用户登录

游客身份登录,可以查看仓库并下载依赖但是不能配置nexus

在这里插入图片描述

默认管理员身份登录
user:admin 
pass:admin123

登录后界面:
在这里插入图片描述

1.2 Blob Stores

依赖index存储目录,默认存储在default下:/sonatype-work/nexus3/blobs/default;

在这里插入图片描述

也可以自己新建一个目录专门存储某个库的索引,后面创建repository时可以选择;

另外,下载或上传到nexus3.10中的jar是被加密存储在\sonatype-work\nexus3\db下

1.3 repository

nexus默认创建了几个仓库。maven-aliyun是手动添加的

在这里插入图片描述

group:是一个仓库组,可包含hosted和proxy两种库,下载时按配置顺序从中依次查找
hosted:一般部署我们自己项目打包的jar,供内部人员下载
proxy:代理远程仓库,maven-central是默认maven中央仓库代理,maven-aliyun是后加的阿里远程库代理,
通过代理从远程库中下载的依赖都会被缓存到nexus的proxy库中

使用时,可以将maven-aliyun添加到maven-public中,常用的库靠前,如下:
在这里插入图片描述
在这里插入图片描述
配置alimaven代理库:配置Proxy的Remote storage为阿里的远程库地址
在这里插入图片描述
创建hosted和proxy库是需要指定Version policy:在这里插入图片描述

release:专用于部署发布版本的jar
snapshot:专用于部署快照版本的jar,jar都是以-SNAPSHOT结尾,pom中version需以-SNAPSHOT(必须大写)结尾
mixed:可包含release和snapshot版本

创建hosted类型仓库时,需要将Deployment policy设为Allow redeploy,否则无法部署jar:
在这里插入图片描述

1.4 Privileges

`数据权限`:repository权限有两种类型,`repository admin``repository view`,
每种类型又有6种权限标识,分别是:*,add,browse、delete、edit、read,*包含其它5种权限,
也可以自定义操作标识,正常系统的生成权限足够使用

1.5 Roles

用户角色,新建一个角色,指定该角色可对哪些库进行哪些操作,如下
在这里插入图片描述

1.6 Users

因为默认的anonymous游客用户只能查看无法部署jar,而admin是管理员身份主要用于配置nexus,所以新建一个可以部署查看jar但不能配置nexus的用户,只需要将该创建的role赋给user,如下:
在这里插入图片描述
在这里插入图片描述

1.7 anonymous

普通未登录用户,都是游客用户,正常如果想要下载依赖,需要勾上Allow access,如下
在这里插入图片描述
当然,为了安全性需要控制外界游客用户对私库的访问,如下
在这里插入图片描述
再次无痕查看游客访问后的页面

在这里插入图片描述

1.8 Tasks

定时任务Tasks,新建一个Maven - Delete unused SNAPSHOT类型定时任务,定期清理过期不使用快照版依赖:
在这里插入图片描述
定时任务官网介绍

二、删除原有,重建仓库(可直接跳四)

2.1 创建blob存储

在这里插入图片描述

2.2 创建hosted类型的maven

在这里插入图片描述

2.3 创建一个proxy类型的maven仓库

如上创建的maven-aliyun代理仓库

2.4 创建仓库组group

在这里插入图片描述
在这里插入图片描述
3.5 查看已创建
在这里插入图片描述

三、测试使用配置私服对接(可直接跳四)

3.1 查看maven-group仓库下的文件此时为空

在这里插入图片描述

3.2 本地maven的settings.xml文件配置

1、server配置:

   <!-- 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> 

在这里插入图片描述
2、mirror配置:(注释之前alimaven,添加私有)

  <mirror>     
        <id>nexus-releases</id>     
        <mirrorOf>*</mirrorOf>     
        <url>http://192.168.42.118:8888/repository/maven-group/</url>     
    </mirror>

3、profile配置

  <profile>    
      <id>nexus</id>    
      <repositories>    
        <repository>    
          <id>nexus-releases</id>    
          <url>http://nexus-releases</url>    
          <releases><enabled>true</enabled></releases>    
          <snapshots><enabled>true</enabled></snapshots>    
        </repository>    
      </repositories>    
      <pluginRepositories>    
         <pluginRepository>    
                <id>nexus-releases</id>    
                 <url>http://nexus-releases</url>    
                 <releases><enabled>true</enabled></releases>    
                 <snapshots><enabled>true</enabled></snapshots>    
               </pluginRepository>
         </pluginRepositories>    
    </profile>

4、activeProfile配置

<activeProfiles>    
  <activeProfile>nexus</activeProfile>    
</activeProfiles>

在这里插入图片描述

3.3 pom文件添加

<distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <url>
                http://192.168.42.118:8888/repository/maven-public/
            </url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>
                http://192.168.42.118:8888/repository/maven-snapshots/
            </url>
        </snapshotRepository>
    </distributionManagement>

在这里插入图片描述

注意repository的id需要和settings中server的id一致,也就是以server指定的用户登录进行上传部署,
普通游客没有权限部署,部署命令:`mvn clean deploy`

四、再次重新整理清晰版

4.1 整体仓库浏览介绍

在这里插入图片描述
0 创建maven-use设置仓库数据保存位置
在这里插入图片描述

`注意此处创建的maven-use后面创建仓库都选择用它`

1 创建maven-aliyun-release仓库
在这里插入图片描述

`注意选择maven-use`

2 创建maven-aliyun-snap仓库
在这里插入图片描述

`注意选择maven-use`

3 创建maven-local-release仓库
在这里插入图片描述
4 创建maven-local-release仓库
在这里插入图片描述
5 定位浏览仓库信息
在这里插入图片描述

4.2 settings文件对接

    <!-- nexus私有仓库对接 -->  
    <server>    
      <id>nexus-group</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>
`此处原先配置的alimaven可直接注释掉了,因为私有仓库已经对它进行了代理,所以此处直接使用私有仓库即可`
      <mirror>     
            <id>nexus-group</id>     
            <mirrorOf>*</mirrorOf>     
            <url>http://192.168.42.118:8888/repository/private-nexus-group/</url>     
        </mirror>    
`此处配置后后就不需要在每个项目pom中再单独配置其私有仓库了 `
<profiles>
    <profile>   
      <!-- 此id下面会用到 -->  
      <id>nexus</id>   
      <repositories>    
        <repository>    
          <id>nexus-group</id>    
          <url>http://192.168.42.118:8888/repository/private-nexus-group/</url>    
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
          </releases>    
           <!-- 是否允许SNAPSHOTS类版本 -->  
          <snapshots>
            <enabled>true</enabled>
          </snapshots>    
        </repository>     
      </repositories>    
      <pluginRepositories>    
         <pluginRepository>    
            <id>nexus-group</id>    
            <url>http://192.168.42.118:8888/repository/private-nexus-group/</url>    
            <layout>default</layout>
            <releases>
              <enabled>true</enabled>
            </releases>    
            <snapshots>
              <enabled>true</enabled>
            </snapshots>    
          </pluginRepository>     
      </pluginRepositories>    
    </profile>
 `使上面profile生效`
 <activeProfiles>    
      <activeProfile>nexus</activeProfile>    
    </activeProfiles>
配置完成保存

4.3 其它操作

1、 删除本地自定义仓库下已经生成的所有文件
2、 重启idea
在这里插入图片描述

`等待引入文件后再次查看本地自定义仓库文件目录和私有仓库信息发现都生成相关信息`

在这里插入图片描述
在这里插入图片描述

`观察即可发现,文件一样的。因为本地的就是从远程私有仓库拉取的。
远程私有仓库又是从代理的alimaven仓库拉取的`

4.3 补充说明

1 上传本地jar包与引入

上传:

在这里插入图片描述

引入在对应pom文件中直接引入即可。
`对即将打包后的项目进行直接上传仓库:(未验证)`
<distributionManagement>
        <!-- 自己创建的其它类型的仓库 -->
        <repository>
            <!-- 对应settings.xml文件中的server标签的id -->
            <id>nexus-releases</id>
            <url>
               http://192.168.42.118:8888/repository/private-nexus-group/
            </url>
        </repository>
        <!-- 自己创建的snapshots版本类型的仓库 -->
        <snapshotRepository>
            <!-- 对应settings.xml文件中的server标签的id -->
            <id>nexus-snapshots</id>
            <url>
                http://192.168.42.118:8888/repository/maven-snapshots/
            </url>
        </snapshotRepository>
    </distributionManagement>

4.4 问题和解决

`如出现引入不了文件,可操作:`

在这里插入图片描述

或者查看本地仓库是否存在,私有nexus仓库中是否有该文件。对比分析,
暴力方式就是直接是再删除本地所有文件重新引入所有
远程没有可先上传或其它方式上传
mvn clean package -DskipTests docker:build  -DpushImage 
`打包时候错误was cached in the local repository, resolution will not be reattempted until the 
update interval of nexus-group has elapsed or updates are forced解决`

在这里插入图片描述

mvn clean deploy
`错误[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException`解决

pom中添加

  <build>
        <plugins>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <altDeploymentRepository>
                        internal.repo::default::file://${project.build.directory}/maven-test
                    </altDeploymentRepository>
                </configuration>
            </plugin>
        </plugins>
    </build>

在这里插入图片描述

上一篇:linux下nexus企业maven私有仓库的搭建——<01>

参考文章:

https://blog.csdn.net/vipbupafeng/article/details/80232566

https://blog.csdn.net/xuxian6823091/article/details/81154757

https://blog.csdn.net/weixin_44086475/article/details/105762183

https://www.cnblogs.com/tyhj-zxp/p/7605879.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值