marven系列8-nexus服务器仓库的简单使用

仓库类型

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

点击顶部设置,然后点击左侧仓库
《marven系列8-nexus服务器仓库的简单使用》

nexus仓库分三种
– hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件
– proxy 代理仓库:代理公共的远程仓库
– group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。

在创建 repository之前,还是需要先设定一个指定的文件存储目录,便于统一管理。
《marven系列8-nexus服务器仓库的简单使用》

默认在/sonatype-work/nexus3/blobs/的Name下

《marven系列8-nexus服务器仓库的简单使用》

创建Proxy Repository代理仓库

《marven系列8-nexus服务器仓库的简单使用》
选择marven(proxy)
《marven系列8-nexus服务器仓库的简单使用》

《marven系列8-nexus服务器仓库的简单使用》

《marven系列8-nexus服务器仓库的简单使用》

其他配置保持默认即可

其中代理仓库的地址常用有

jboss的maven中央仓库地址:http://repository.jboss.com/maven2/

阿里云的maven中央仓库地址:http://maven.aliyun.com/nexus/content/groups/public/

apache的maven中央仓库地址:http://repo.maven.apache.org/maven2/

我们可以建好几个proxy repository,将远程maven仓库到group仓库中,其中代理仓库国内的要放在国外的之前,因为国内的访问速度比国外的快。

这样的加入group资源库的顺序就是 hosted仓库>国内proxy仓库>国外proxy仓库
以此提高访问下载效率

创建hosted repository仓库

宿主仓库分为三种Releases、SNAPSHOT、Mixed

Releases: 一般是已经发布的Jar包
Snapshot: 快照版本
Mixed:混合的
《marven系列8-nexus服务器仓库的简单使用》

《marven系列8-nexus服务器仓库的简单使用》

创建group repository 组仓库

《marven系列8-nexus服务器仓库的简单使用》

《marven系列8-nexus服务器仓库的简单使用》

注意组仓库中仓库的顺序:
hosted repositories仓库放在proxy repositories仓库之前,因为一个group仓库中可以涵括这些宿主仓库和代理仓库。而一整个的group是作为一个public,一个接口给别人使用的。所以当查找jar包的时候,如果代理仓库在前面,那就是先从远程去查找jar,而不是先从托管资源库(本地仓库)去查找是否有jar。这样访问外网的消耗比起来在本地查找,当然是将托管资源库放在代理资源库之前的优先位置了。

marven配置私服

点击copy即可获取仓库地址
《marven系列8-nexus服务器仓库的简单使用》

在marven安装目录的配置文件conf/setting中修改添加配置
《marven系列8-nexus服务器仓库的简单使用》

《marven系列8-nexus服务器仓库的简单使用》

在pom.xml中添加org.projectlombok依赖

<dependencies>
         <!--项目要使用到junit的jar包,所以在这里添加junit的jar包的依赖-->
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.9</version>
             <!-- 可选依赖,是否向下传递,false传递,true不传递 -->
             <optional>false</optional>
         </dependency>   
          <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency>     
     </dependencies>

《marven系列8-nexus服务器仓库的简单使用》
点击jar文件
《marven系列8-nexus服务器仓库的简单使用》
blob reference冒号后面的值是二进制文件的文件名,nexus把下载下来的所有文件都转化成了byte文件,所以在上面创建blob store位置

《marven系列8-nexus服务器仓库的简单使用》

将jar包上传到nexus

在maven的settting.xml文件中配置hosted仓库

<server>
      <id>shadow_host</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

  </servers>

在pom.xml中添加

 <distributionManagement>
        <!-- 发布版地址 -->
        <repository>
            <id>shadow_host</id>
            <url>http://144.202.91.42:8081/repository/shadow_host/</url>
        </repository>
        <!-- 快照版地址 -->
        <snapshotRepository>
            <id>shadow_host</id>
            <url>http://144.202.91.42:8081/repository/shadow_host/</url>
        </snapshotRepository>
    </distributionManagement>

由于建立的host仓库是mixed的,所以快照版和发布版jar都发布到这个host仓库,一般会建立两个host仓库,一个快照版一个发布版,分别配置连个仓库的地址

点击first项目右键run as -》marven build-》输入deploy run即可

查看shadow_host仓库
《marven系列8-nexus服务器仓库的简单使用》
发布成功

获取发布到nexus服务器上的构件

添加对first构件的依赖即可
《marven系列8-nexus服务器仓库的简单使用》

闲言碎语

本章只演示了mixed类型的host仓库,下一节演示release和snapshot类型的host仓库和用参数自动控制发布的版本是快照版还是发布版

参考

点赞

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注