idea maven依赖问题

本文总结了在使用Maven和IDEA过程中遇到的各种依赖问题及解决方案,包括依赖包下载失败、插件版本冲突、系统路径配置、依赖分析工具的使用等。通过调整pom.xml文件、更新镜像源、使用MavenHelper插件等方式,有效解决了项目中的依赖问题。
摘要由CSDN通过智能技术生成

今年发现项目几乎没有出现类似的依赖报错,原因是我现在呆的公司,依赖相关的需求等问题都是老大他们决定的,且项目大都是旧的项目很少出现大的改动。而且依赖是公司自己开发的项目,即使改动也只是另一个部门维护,维护好了后,我只需要改依赖的版本,没有做任何添加的dependency。
怕自己很久不操作会直接忘掉,于是把比较难忘的做个汇总。

maven有一些包无法下载 依赖飘红

打开springboot项目,没有maven依赖(右侧栏没有maven project) 

ctrl+shift+A 输入maven 选择 add maven projects 选择项目中的pom文件 即可出现

依赖包不下载

maven依赖全部红不会加载IDEA中Maven依赖包下载不了的问题解决方案汇总_谜-CSDN博客_idea下载maven依赖包

maven单个飘红  查看版本依赖发现1.3.2没有下载   原因:1.3.5高版本存在,低版本自动忽略

<plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>

            <!-- geelynote maven的核心插件之-complier插件默认只支持编译Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml里面加上 增加编译插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>

            <!-- mybatis-generator自动生成代码插件 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <!--<scope>runtime</scope>-->
                        <version>5.1.46</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>

改成

<plugins>
            <!-- geelynote maven的核心插件之-complier插件默认只支持编译Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml里面加上 增加编译插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>

            <!-- mybatis-generator自动生成代码插件 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <!--<scope>runtime</scope>-->
                        <version>5.1.46</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>

导包问题

 由于项目需求,短信验证码的接口需要换成阿里大于的,但是尴尬的发现阿里大于的jar包没有maven版本的
其中jar放在当前工程目录lib下。

<!-- 阿里短信 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>alisms</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/alisms-1.0.jar</systemPath>
</dependency>
<scope>system</scope>

被依赖项不会从maven仓库抓,而是从本地系统文件拿

最后(不知道这一步有何用   没测试过)

网上很多的教程缺了这样一步之后就会导致虽然本地可以运行,但是只要使用maven打包就不行,因为maven没有将本地的jar也打到生成的包中

在pom中给spring boot的打包插件设置一下includeSystemScope参数即可

<build>
  <plugins>
    <plugin
>
       <groupId
>org.springframework.boot</groupId>
       <artifactId
>spring-boot-maven-plugin</artifactId
       
<configuration>
          <includeSystemScope
>true</includeSystemScope
       
</configuration>
     </plugin
>
  </plugins
>
</build
>

导入项目后出现了好几个Library xxx has broken classes paths 

导入项目后在Project Structure窗口(Ctrl + Alt + Shift + S)出现包没有引入;会导致项目上一些文件显示未找到,但是检查pom.xml文件是正常未报错(飘红)

 于是,我察觉到是idea这个IDE的  maven的配置出了问题,在File- Setting-- Build Tools找到maven;  如图,只需把Maven home path下面三个路径改为同一个目录。

 settings.xml配置文件设置的仓库位置  和下一行Local repository仓库位置应该是一致的

 E:\work\apache-maven-3.6.1\conf\settings.xml
 E:\work\repo

Dependency Analyzer工具 用于解决依赖突

IDEA插件,叫Maven Helper,在 File->Settings->Plugins里安装就好了,另外这个工具依赖maven intergration,在安装后一定也要把它打上勾,然后重启IDEA。重启后,你打开你的pom.xml,编辑器左下角会多出来个“Dependency Analyzer”,打开后会发现,丫把所有依赖包的版本和冲突全都列出来了,而且还会把冲突包的路径显示出来,这时候你只要把冲突包的所有低版本从pom中exclude掉就好了

 Maven Helper解决Maven插件冲突

 maven是个依赖管理工具,俗称仓库     

Maven Helper解决Maven依赖冲突的插件 ,  当发现依赖下载了还报找不到类的错误时

打开项目中的pom文件 ; 找到代码左下角Dependency Analyzer

所有依赖包的版本和冲突全都列出来了,而且还会把冲突包的路径显示出来

找到冲突,右键  Exculde排除冲突版本的jar包

特殊问题

最近6-7月发生这个错,我把本地的仓库删掉都没用,只有这个文件,可能是配置我呢见那里错了吗

Maven Dependencies 文件夹丢失

使出绝招重启一下电脑    ——   还是不行,下面两图为idea工具出现的现象,上图为maven仓库,发现没有下载jar包

在这里插入图片描述

Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.0.4.RELEASE from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.0.4.RELEASE from/to nexus (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.0.4.RELEASE/spring-boot-starter-parent-2.0.4.RELEASE.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. more... (Ctrl+F1)

解决方法:(转载IDEA Maven 导入jar 的问题 - 所有的都正常,就是导入的文件一直是XXXX..pom.lastUpdated 后缀的文件_微笑的 Java-CSDN博客

IDEA Maven —— 导入jar 的问题 - 所有的都正常,就是导入的文件一直是XXXX..pom.lastUpdated 后缀的文件

<mirror>
		<id>nexus</id>
		<name>internal nexus repository</name>
		<url>http://repo.maven.apache.org/maven2</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
 
<mirrorOf>central</mirrorOf>  这个错  因为mirrorOf 配置为central所以jar找不到

改为:   这是国内阿里云镜像库  
 <mirror>
		<id>nexus-aliyun</id>
		<mirrorOf>*</mirrorOf>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>

曾经尝试的方法(可不看)

可以上网   也没有work offline

怀疑过依赖包网站的网络不好导致没法下载   https://mvnrepository.com/ 直接下载到本地   太繁琐  治标不治本

猜测过版本冲突      MavenHelper检查。。。

重启过电脑         

最后是我配置过的镜像源出问题   

IDEA中Maven依赖包下载不了的问题解决方案汇总_谜-CSDN博客_idea下载maven依赖包先看一下这个100赞的   

如  spring-boot-starter-mail   总是不能下载    这就需要在https://mvnrepository.com/ 搜索下载

 https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail

原因可能是   spring-boot-starter-parent定义了版本,spring-boot-starter-mail没有定义版本

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

回去把依赖添加版本看行不行

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    <version>2.0.4.RELEASE</version>
</dependency>
 

点击 view all  下载文件

Central Repository: org/springframework/boot/spring-boot-starter-mail/2.3.1.RELEASE

idea org.apache.maven.plugins:maven-source-plugin飘红

咋搞

Failed to read artifact descriptor for xxx:jar   一些依赖无法下载

这问题我有时候成功    有时候不行 

  • 就是重启 
  • 打开setting——>Compiler——>勾选Build Project automatically

1. 删除Project Structure-Libraries中划了红线的那个jar,同时删除对应目录下的文件和文件夹,这里我删除了原来的MyBatis目录。

2. 打开IntelliJ 右边的Maven Project,点击左上角那个刷新的按钮(Reimport All Maven Projects),注意请保证处于联网状态,这时候Maven会自动下载相关的依赖包。
原文链接:https://blog.csdn.net/u011420057/article/details/72582925

springboot下载的依赖

填坑之路!SpringBoot导包坑之spring-boot-starter-parent_大誌的博客-CSDN博客+

Unused import statement解决方法 

未使用导入语句
原因:提醒你导入了但没有使用  可以删掉的意思
file下有invalidate caches/restart   清除缓存再重启

pom.xml->右键maven->reimport

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huang_ftpjh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值