导入maven依赖以后报红

新建项目以后直接复制的依赖,但是刷新maven都不好使
file-20241225202111022.png

然后开始检查maven下的conf包下的setting.xml文件里的内容,
file-20241225213856030.png
然后看仓库地址配置的也是我自己的,

<offline>false</offline>

这个是默认的就可以,  offline:值为true/false,true表示构建系统在离线模式下执行,默认为false;这个没有问题,
再就是这个镜像的仓库地址,也没有问题

<mirrors>  
    <mirror>        <id>nexus-aliyun</id>  
        <mirrorOf>*,!jeecg,!jeecg-snapshots,!getui-nexus</mirrorOf>  
        <name>Nexus aliyun</name>  
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
    </mirror>    <mirror>        <id>aliyunmaven</id>  
        <mirrorOf>*,!getui-nexus</mirrorOf>  
        <name>阿里云公共仓库</name>  
        <url>https://maven.aliyun.com/repository/public</url>  
    </mirror></mirrors>

然后就是重启清楚idea缓存,也不行,刷新maven也不行,然后看视频看弹幕说是因为pom.xml文件中的<dependencyManagement>标签导致的,先把这个标签注释掉,然后下载依赖,果然还是网友啊,大佬是真多,注释掉以后就可以成功下载了。下载完以后再把注释打开就可以了。

  <dependencyManagement>
    <dependencies>  
      <!--spring boot 2.2.2-->  
      <dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-dependencies</artifactId>  
        <version>2.2.2.RELEASE</version>  
        <type>pom</type>  
        <scope>import</scope>  
      </dependency>      <!--spring cloud Hoxton.SR1-->  
      <dependency>  
        <groupId>org.springframework.cloud</groupId>  
        <artifactId>spring-cloud-dependencies</artifactId>  
        <version>Hoxton.SR1</version>  
        <type>pom</type>  
        <scope>import</scope>  
      </dependency>      <!--spring cloud alibaba 2.1.0.RELEASE-->  
      <dependency>  
        <groupId>com.alibaba.cloud</groupId>  
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>  
        <version>2.1.0.RELEASE</version>  
        <type>pom</type>  
        <scope>import</scope>  
      </dependency>      <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->  
      <dependency>  
        <groupId>mysql</groupId>  
        <artifactId>mysql-connector-java</artifactId>  
        <version>${mysql.version}</version>  
      </dependency>  
      <dependency>        <groupId>com.alibaba</groupId>  
        <artifactId>druid</artifactId>  
        <version>1.1.16</version>  
      </dependency>      <dependency>        <groupId>org.mybatis.spring.boot</groupId>  
        <artifactId>mybatis-spring-boot-starter</artifactId>  
        <version>${mybatis.spring.boot.version}</version>  
      </dependency>      <dependency>        <groupId>junit</groupId>  
        <artifactId>junit</artifactId>  
        <version>${junit.version}</version>  
      </dependency>      <dependency>        <groupId>log4j</groupId>  
        <artifactId>log4j</artifactId>  
        <version>${log4j.version}</version>  
      </dependency>      <dependency>        <groupId>org.projectlombok</groupId>  
        <artifactId>lombok</artifactId>  
        <version>${lombok.version}</version>  
        <optional>true</optional>  
      </dependency>    </dependencies>
  </dependencyManagement>

那么为什么dependencyManagement 里面的依赖无法下载呢?

原来<dependencyManagement>只是用于父工程管理依赖的,用于统一管理jar的版本。子工程需要使用相应的jar引入依赖即可,这时才真正的使用到相应jar,才会去下载。

  • 方案一:
    先把 <dependencyManagement> </dependencyManagement> 这对标签注释掉或者去掉,就可以下载了,下载完在加回来即可

  • 方案二:
    或者不去处理,子工程需要使用相应的jar引入依赖即可,这时会自动去下载jar,一顿操作之后发现可行!
    以前学习的maven的时候学过,但是忘记了
    https://www.cnblogs.com/javaxubo/p/17498473.html 这里说了只是声明依赖,并不实现引入

posted @   哩个啷个波  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示