安装maven配置私服Nexus3

本文详细介绍了如何安装和配置Maven私服Nexus3,包括启动Nexus,修改配置,创建和管理不同类型的仓库,如宿主仓库、代理仓库和仓库组。此外,还讲解了如何上传和下载项目骨架到私有仓库,以及在IDEA中配置使用Nexus3,并提供了设置镜像的步骤,以加速依赖下载。
摘要由CSDN通过智能技术生成

安装maven私服Nexus3

预置条件
  1. Java环境
  2. Maven环境
  3. nexus安装包
打开解压目录:
	-> nexus-3.32.0-03    安装目录
		 ..... 主要文件夹
		 -> bin			命令文件目录
		 -> etc			配置文件目录
	-> sonatype-work	   工作目录
# 进入文件bin目录
nexus-3.32.0-03 -> cd ./nexus-3.32.0-03/bin
# 运行nexus
bin -> ./nexus run
访问网址

http://localhost:8081/

登录账号密码,在安装文件目录下

配置nexus3

找到安装根目录: /apache-latest-nexus-3.32/nexus-3.32.0-03/etc

修改 nexus-default.properties

仓库名作用
hosted 宿主仓库要用于部署无法从公共仓库获取的构件以及自己或第三方的项目构件(存放本公司开发的jar包(正式版本、测试版本))
proxy 代理仓库代理公共的远程仓库
group 仓库组Nexus 通过仓库组统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库(使用时连接组仓库,包含Hosted(宿主仓库)和Proxy(代理仓库))
release仓库内部的模块中release模块的发布仓库
snapshots发布那些非release版本, 非稳定版本
替换nexus远程仓库地址

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k3TuXGmf-1645232709078)(/Users/zwl/Library/Application Support/typora-user-images/image-20211109102026379.png)]

上传本地项目骨架到私服

  1. 新建项目

  2. 引入maven骨架插件

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-archetype-plugin</artifactId>
      <version>3.2.0</version>
    </plugin>
    
  3. 执行创建Maven模板命令

    在项目下pox.xml目录下执行下面命令

    mvn archetype:create-from-project
    
  4. 进入当前目录生成的文件夹,在执行install

    cd target\generated-sources\archetype
    mvn install ##生成到本地的repository中,在repository文件夹中的archetype-catalog.xml中
    
  5. 在生成的pom.xml文件中添加私服的地址

    <distributionManagement>
      <repository>
        <id>releases</id> <!-- 自定义releases版的id id要和setting文件中server的ID对应-->
        <name>Nexus Release Repository</name>
        <url>http://XXXX/repository/maven-releases/</url> <!-- 私服中releases的仓库地址 -->
      </repository>
      <snapshotRepository>
        <id>snapshots</id> <!-- 自定义snapshots版的id id要和setting文件中server的ID对应-->
        <name>Nexus Snapshot Repository</name>
        <url>http://xxx/repository/maven-snapshots/</url> <!-- 私服中snapshots的仓库地址 -->
      </snapshotRepository>
    </distributionManagement>
    
  6. 配置本地setting文件

    <servers>
      <server>
       <id>releases</id>
       <username>admin</username>
       <password>admin</password>
      </server>
      <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin</password>
      </server>
    </servers>
    
    ## 检查本地setting.xml配置是否有错误
    mvn help:effective-settings    
    
  7. 项目上传

    在第4步的目录中执行如下命令即可

    mvn deploy
    

从私服中下载项目骨架

  1. 在setting.xml中配置镜像的地址

    <mirror>
      <id>Nexus-aliyun</id>
      <!-- 关于mirrorOf,如果有同名的mirrorOf,那么只会匹配第一个,如果有<mirrorOf>*</mirrorOf>,优先匹配名字完全相同的,其次匹配通配符 -->
      <mirrorOf>central</mirrorOf> 
      <name>Nexus aliyun</name>
      <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    
    </profiles>
      <profile>
        <id>nexus-mr</id>
        <repositories>
          <!-- 配置的顺序决定了下载 jar 包的顺序 -->
          <!--  maven下载时,按顺序查找,优先找nexus,找不到再找central  -->
          <!-- 这里nexus为我的私服地址 -->
          <repository>
            <id>nexus</id>
            <url>http://XXX/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </repository>
          <!-- 中央仓库此处可省略 -->
          <repository>
            <id>central</id>
            <url>https://maven.aliyun.com/repository/central</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </repository>
        </repositories>
        <pluginRepositories>
          <pluginRepository>          
            <id>nexus</id>
            <url>http://XXX/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </pluginRepository>
          <pluginRepository>          
            <id>central</id>
            <url>https://maven.aliyun.com/repository/central</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </pluginRepository>
        </pluginRepositories>
      </profile>
    </profiles>
     <activeProfiles>
       <activeProfile>nexus-mr</activeProfile>
    </activeProfiles>
    
    1. 在IDEA中添加私服中的项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值