软件编程
位置:首页>> 软件编程>> java编程>> idea 与 maven 使用过程中遇到的问题及解决方案

idea 与 maven 使用过程中遇到的问题及解决方案

作者:java编程艺术  发布时间:2021-10-07 02:34:24 

标签:idea,maven,使用

1. maven项目导入idea报ComponentLookupException异常

1.1. 问题描述

最近将IDEA 升级到 IntelliJ IDEA 2021.3.2,在将maven项目导入IDEA后,maven build时报如下异常:

org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model.validation.DefaultModelValidator: method <init>()V not found
  at org.jetbrains.idea.maven.server.embedder.CustomModelValidator.<init>(Unknown Source)
  while locating org.jetbrains.idea.maven.server.embedder.CustomModelValidator
  at ClassRealm[maven.ext, parent: ClassRealm[plexus.core, parent: null]] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
  while locating org.apache.maven.model.validation.ModelValidator annotated with @com.google.inject.name.Named(value=ide)
1 error
      role: org.apache.maven.model.validation.ModelValidator
  roleHint: ide

1.2.解决方案

这个问题是IntelliJ IDEA 2021.3.2 不兼容导致的。 我使用的Maven版本是3.8.3, 将Maven版本降至3.8.1 或 使用IDEA Bundled(Maven3)即可解决。

Maven 3.x 下载地址

idea 与 maven 使用过程中遇到的问题及解决方案

2. IDEA无法加载maven本地仓库的文件

2.1.问题描述

如果公司 Nexus * 里面没有对应的依赖jar包,但本地仓库有_remote.repositories文件,
这种情况下IDEA无法加载本地的jar包,导致MAVEN依赖变成红色

idea 与 maven 使用过程中遇到的问题及解决方案

_remote.repositories 内容类似如下:

idea 与 maven 使用过程中遇到的问题及解决方案

2.2.解决方案

查找并删除所有_remote.repositories文件 clear_remote.repositories.bat

set REPOSITORY_PATH=D:\maven\repository
echo is finding all _remote.repositories file ...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*_remote.repositories*"') do (
   del /s /q %%i
)
echo delete all _remote.repositories has finished
pause

3.删除maven下载失败的jar包

3.1. 问题描述

maven针对更新失败的依赖,在对应的文件夹中都生成了lastUpdated后缀结尾的文件,这些文件有时会导致IDEA不能正常加载这些本地依赖。

idea 与 maven 使用过程中遇到的问题及解决方案

3.2.解决方案

查找并删除所有包含lastUpdated的文件 clear_lastUpdated.bat

set REPOSITORY_PATH=D:\maven\repository
echo is finding all lastUpdated file ...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
   del /s /q %%i
)
echo delete all lastUpdated has finished
pause

4. 删除_maven.repositories文件

4.1.问题描述

Maven tries to update your jar from the old location (as saved in _maven.repositories) and fails. The presumtion here is that the same aftifact on a different remote repository might be different.

Maven试图从旧位置(保存在_maven.repositories中)更新jar,但失败了。这里的假设是,相同的aftifact 在不同的远程存储库上可能是不同的。

有时此文件会导致jar更新或加载失败

4.2.解决方案

查找并删除所有包含_maven.repositories的文件 clear_maven.repositories.bat

set REPOSITORY_PATH=D:\maven\repository
echo is finding all _maven.repositories file ...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*_maven.repositories*"') do (
   del /s /q %%i
)
echo delete all _maven.repositories has finished
pause

来源:https://blog.csdn.net/penriver/article/details/124675403

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com