Maven私有仓库的基本配置

Maven仓库,私有仓库的设置(在 settings.xml 中配置远程仓库)

     1: 索引更新:将下载的nexus-maven-repository-index.zip包中替换  D:\Nexus\sonatype-work\nexus\indexer\central-ctx
     如果工厂换了,那么索引页需要更换

     2:  配置镜像,覆盖中央仓库的默认地址
          <mirrors>
              <mirror>
              <id>central</id>
              <mirrorOf>nexus</mirrorOf><!--如果想为所有的仓库做镜像那么可以改为:<mirrorOf>*</mirrorOf>-->
              <name>Human Readable Name for this Mirror.</name>
              <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
              </mirror>
         </mirros>

         pom.xml文件中的配置为(在不修改默认配置的情况下):
            <repository>
                <id>nexus</id>
                <name>nexus repository</name>
                <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
         这就表示我们项目中所有的依赖不会到pom.xml文件中的url中找了,而是会倒我们镜像中配置的url中找,
         两者之间是通过id来进行一一对应关联的
     
      3: 如果我们将我们项目pom里面的仓库设置删除、那么我们有一个默认的仓库设置,但是不支持快照版的发布,
     如果我们修改这一默认的配置,就得使用profile。如下配置:
     在我们本地仓库的settings.xml文件中:
           <profiles>
       <profile>
          <id>central-repos</id>
          <repositories>
        <repository>
          <id>central</id>
          <name>Central</name>
          <url>http://central</url><!--这个地址无效,因为我们为所有的仓库配置了镜像-->
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
          </repositories>
        </profile>
      
      <activeProfiles>
        <activeProfile>central-repos</activeProfile>
      </activeProfiles>
   
     4: 通过以上配置之后我们就可以在nexus上来搜索我们的项目依赖了,而不用去其他的网上maven仓库中查找

配置Maven私有仓库,可以使用Sonatype Nexus 3作为Maven仓库管理器。 以下是配置Nexus 3作为Maven私有仓库的步骤: 1. 安装Nexus 3 可以从Sonatype官网下载Nexus 3,然后按照说明进行安装和配置。 2. 创建Maven仓库 在Nexus 3中创建Maven仓库,可以通过以下步骤完成: - 登录到Nexus 3的Web界面,并进入“Repositories”页面。 - 点击“Create Repository”按钮,并选择“Maven(hosted)”类型。 - 输入仓库的名称和URL,并选择存储位置等配置信息。 - 点击“Create Repository”按钮,完成仓库创建。 3. 配置MavenMaven的settings.xml文件中配置Nexus 3作为私有仓库,可以通过以下步骤完成: - 打开Maven的settings.xml文件,一般位于${user.home}/.m2/目录下。 - 在<settings>标签内添加如下配置: ``` <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://nexus3.example.com/repository/maven-releases/</url> </mirror> </mirrors> ``` 其中,nexus3.example.com/repository/maven-releases/是Nexus 3仓库的URL。 4. 发布和使用Maven包 在使用Nexus 3作为Maven私有仓库时,可以通过以下步骤发布和使用Maven包: - 在项目的pom.xml文件中配置Nexus 3仓库的URL等信息。 - 使用Maven命令发布项目的Maven包到Nexus 3仓库中。 - 在其他项目的pom.xml文件中添加Nexus 3仓库的URL,然后使用Maven命令从Nexus 3仓库中获取依赖。 以上是配置Nexus 3作为Maven私有仓库基本步骤,具体操作可以根据实际情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值