构建 Maven 项目时,出现org.codehaus.plexus.component.repository.exception.

526 阅读1分钟

异常信息提示

今天在使用 IDEA 2021 构建 Maven 项目的时候,发生了以下错误: image.png

org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) [Guice/ErrorInjectingConstructor]: NoSuchMethodError: DefaultModelValidator: method <init>()V not found
  at CustomModelValidator.<init>(CustomModelValidator.java:36)
  while locating CustomModelValidator
  at ClassRealm[maven.ext, parent: ClassRealm[plexus.core, parent: null]]
      \_ installed by: WireModule -> PlexusBindingModule
  while locating ModelValidator annotated with @Named(value=ide)

Learn more:
  https://github.com/google/guice/wiki/ERROR_INJECTING_CONSTRUCTOR

1 error

======================
Full classname legend:
======================
CustomModelValidator:  "org.jetbrains.idea.maven.server.embedder.CustomModelValidator"
DefaultModelValidator: "org.apache.maven.model.validation.DefaultModelValidator"
ModelValidator:        "org.apache.maven.model.validation.ModelValidator"
Named:                 "com.google.inject.name.Named"
PlexusBindingModule:   "org.eclipse.sisu.plexus.PlexusBindingModule"
WireModule:            "org.eclipse.sisu.wire.WireModule"
========================
End of classname legend:
========================

      role: org.apache.maven.model.validation.ModelValidator
  roleHint: ide

原因

根据百度查阅别人的博客信息,说是因为 IDEA 2021 中适配的 maven 版本过高,我这里使用的是 maven3.9.6,所以解决的思路就是将 maven 的版本降低。

解决方案

重新下载配置 maven,这里我换成了 maven 3.3.9,详细的配置过程参考往期文章 [Maven下载与配置](Maven 配置配置环境变量 配置本地仓库 找到 localRepository 节点,在注释外添加 mirrors 节 - 掘金)

结果

配置成功

image.png