IDEA中Maven构建报错

发布时间 2023-03-25 14:12:58作者: 飞哥传书

报错信息

创建Maven项目后报了如下错误信息

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

1) [Guice/ErrorInjectingConstructor]: NoSuchMethodError: DefaultModelValidator: method 'void <init>()' 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

原因及解决方法

上网搜索后发现可能是由于我安装的Maven版本过高,与IDEA不兼容导致的。笔者安装的Maven是3.9.1,IDEA是2021.2.3。
建议安装3.6.3版本的Maven。