Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)

使用Nexus搭建个人仓库

  • 一、Linux环境下安装Nexus
  • 二、如何创建私有仓库,项目配置私有仓库

Nexus 是一个开源的仓库管理系统,用于管理软件组件和构建。它支持多种仓库管理,包括 Maven、npm、Docker、RubyGems 等。

一、Linux环境下安装Nexus

  1. 下载 Nexus:访问 Sonatype 下载页面 并下载 Nexus Repository Manager 的适当版本。选择 OSS 版本(开源版本)或其他适合您需求的版本。

    填写好一些信息后,就可以下载你需要的版本的安装包。

  2. 将安装包(unix版本)放到你要安装的路径下,解压

tar -zxvf nexus-3.63.0-01-unix.tar.gz

解压后会有两个新的文件夹:

  • nexus-3.63.0-01 : 就是程序目录了,不需要 make等命令安装。
  • sonatype-work: 是 Sonatype Nexus 仓库管理系统的默认工作目录。
  1. (可选)修改启动的端口
    配置文件路径是 /your/install/sonatype-work/nexus3/etc/nexus.properties
    修改的内容是 application-port=8001

  2. 启动项目,参考命令

# 启动
/your/install/nexus-3.63.0-01/bin/nexus start
# 查看状态
/your/install/nexus-3.63.0-01/bin/nexus status
#停止
/your/install/nexus-3.63.0-01/bin/nexus stop
  1. 浏览访问Nexus http://yourip:yourPort
    进入页面后,可能需要进行一定的初始化操作,例如密码重置等。按照要求完成就好了
    Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)_第1张图片

二、如何创建私有仓库,项目配置私有仓库

  1. 创建仓库

仓库类型:

  • Maven2 (Hosted) 仓库:用于存储和管理本地主机的 Maven 构件。这是您上传和管理自己的构件的地方。
  • Maven2 (Group) 仓库 : 用于将多个 Maven 2 仓库组合成一个虚拟的仓库,以便在 Maven 构建中使用这个组合的仓库。
  • Maven2 (Proxy) 仓库: 用于代理远程 Maven 仓库,以提高构建性能并缓存远程依赖项。当构建需要依赖于远程 Maven 仓库中的构件时,Nexus 可以在代理仓库中缓存这些构件。

一般来讲 选 Hosted 就行,输入仓库名车,不需要配置任何东西。
Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)_第2张图片

Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)_第3张图片

  1. 上传依赖到仓库

我目前是用它来当第三方依赖库,即别的公司给你的jar包,统一放到这里来管理。

Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)_第4张图片

Nexus搭建个人仓库,管理第三方依赖(减少使用system依赖)_第5张图片

  1. setting.xml文件配置仓库
  • 配置私仓的镜像信息
  • 配置私仓的仓库信息 并且激活配置哈
  • 配置私仓的账号信息 ,如果你初始化Nexus时,允许任何人访问,那么不需要哈

我的配置文件参考:



<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <localRepository>/Users/nanan/.m2/repositorylocalRepository>
  <servers>
    
    <server>
      <id>nexus-third-party-lib-mirrorid>
      <username>adminusername>
      <password>your-passwordpassword>
    server>
  servers>

  <mirrors>
    
    <mirror>
      <id>ali-serverid>
      <name>阿里云仓库作为主仓name>
      <mirrorOf>centralmirrorOf>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/url>
    mirror>  


    <mirror>
        <id>nexus-third-party-lib-mirrorid>
        <url>http://yourIp:yourPort/repository/third-party-lib/url>
        <mirrorOf>*mirrorOf>
    mirror>


  mirrors>

  <profiles>
    <profile>
         <id>nexusid>
          
         <repositories>
          <repository>
            <id>ali-serverid>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/url>
          repository>
          
          <repository>
            <id>nexus-third-party-libid>
            <url>http://yourIp:yourPort/repository/third-party-lib/url>
          repository>
        repositories>

    profile>  
  profiles>  

  
   <activeProfiles>
    <activeProfile>nexusactiveProfile>
  activeProfiles>
settings>

  1. 你的Maven使用这个配置文件就好了

你可能感兴趣的:(Maven,maven,运维)