Maven依赖解决

本文讲述了在Maven项目中遇到zookeeper依赖冲突的问题,通过检查仓库配置和版本切换,解决SpringCloudstarterzookeeper-discovery依赖的特定版本问题,并介绍了如何使用exclusions属性来排除冲突版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记一次Maven依赖冲突解决

以zookeeper为例

一、问题描述

  1. 当下载zookeeper的2.2.6.RELEASE时,报错
    Could not find artifact org.springframework.cloud:spring-cloud-starter-zookeeper-discovery:pom:2.2.6.RELEASE in central (https://repo.maven.apache.org/maven2)
    在这里插入图片描述
  • 说明在maven仓库中找不到2.2.6.RELEASE这个版本,那么现在我们就应该去看是不是中央仓库配置出了问题,最快验证办法就是下载其他依赖,发现可以正常下载,说明中央仓库配置没出问题。在这里,顺便推荐下面的中央仓库alibaba镜像配置
  <mirrors>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>central</mirrorOf>
     <name>阿里云公共仓库</name>
     <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>central repo</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>apache snapshots</mirrorOf>
     <name>阿里云阿帕奇仓库</name>
     <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>
  <proxies/>
  <activeProfiles/>
  <profiles>
    <profile>  
        <repositories>
           <repository>
                <id>aliyunmaven</id>
                <name>aliyunmaven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <layout>default</layout>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>MavenCentral</id>
                <url>http://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>aliyunmavenApache</id>
                <url>https://maven.aliyun.com/repository/apache-snapshots</url>
            </repository>
        </repositories>             
     </profile>
  </profiles>

当ali镜像找不到时,会去maven中央仓库寻找

  1. 检查中央仓库配置无误后,就应该看仓库中是否存在这个依赖
  • 第一步看maven仓库,maven。(看这个比较麻烦)
  • 第二步看ali镜像仓库,ali-mirror
    在这里插入图片描述
    观察发现确实没有2.2.6.RELEASE这个版本,那么我们可以换成2.2.5的版本
    在这里插入图片描述
  1. 上面换成2.2.5之后,又带来了一个新的问题,那就是spring-cloud-starter-zookeeper-discovery这个依赖,spring自带了一个zookeeper的版本,但是这个zookeeper依赖没有下载,所以报错Cannot resolve org.apache.zookeeper:zookeeper:3.5.3-beta。接下来我们有两种办法:
  • 下载zookeeper:3.5.3-beta版本即可
  • 在spring-cloud-starter-zookeeper-discover排除zookeeper:3.5.3-beta,重新导入其他版本的zookeeper

这里使用第二种办法,版本号已经在父工程中约束

在这里插入图片描述

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值