详述 IntelliJ IDEA 遇到 Maven 项目打开(Open)或者导入(Import)失败的解决方法

December 15, 2023
测试
测试
测试
测试
10 分钟阅读

文章目录

  • 问题背景
  • 解决方法

问题背景

现有一个 Maven 项目,通过 IntelliJ IDEA 的Open或者Import Project来打开或者导入该项目:

unable-import-maven-project
unable-import-maven-project

如上图所示,导入 Maven 项目失败,提示:

Unable to import maven project: See logs for details

就算我们点击Event Log,也获取不到详细的错误信息:

event-log
event-log

这时,我们需要通过Help -> Show Log in Finder来查看错误日志:

show-log
show-log

在我们点击Show Log in Finder之后,会在弹出的目录中找到一个名为idea.log的日志文件,打开该文件,即可查看详细的错误日志:

2020-03-16 14:40:03,808 [13325330]   INFO - ution.rmi.RemoteProcessSupport - Port/ID: 52340/Maven3ServerImpl952a326a 
2020-03-16 14:40:05,385 [13326907]  ERROR -      #org.jetbrains.idea.maven - com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for org.apache.maven.model.path.PathTranslator was bound.
  while locating org.apache.maven.model.path.PathTranslator
    for field at org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator.pathTranslator(Unknown Source)
  at org.codehaus.plexus.DefaultPlexusContainer$1.configure(DefaultPlexusContainer.java:350)

2) No implementation for org.apache.maven.model.path.UrlNormalizer was bound.
  while locating org.apache.maven.model.path.UrlNormalizer
    for field at org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator.urlNormalizer(Unknown Source)
  at org.codehaus.plexus.DefaultPlexusContainer$1.configure(DefaultPlexusContainer.java:350)

2 errors 
java.lang.RuntimeException: com.google.inject.CreationException: Unable to create injector, see the following errors:

1) No implementation for org.apache.maven.model.path.PathTranslator was bound.
  while locating org.apache.maven.model.path.PathTranslator
    for field at org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator.pathTranslator(Unknown Source)
  at org.codehaus.plexus.DefaultPlexusContainer$1.configure(DefaultPlexusContainer.java:350)

2) No implementation for org.apache.maven.model.path.UrlNormalizer was bound.
  while locating org.apache.maven.model.path.UrlNormalizer
    for field at org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator.urlNormalizer(Unknown Source)
  at org.codehaus.plexus.DefaultPlexusContainer$1.configure(DefaultPlexusContainer.java:350)

2 errors
	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543)
	at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:159)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
	at com.google.inject.Guice.createInjector(Guice.java:87)
	at com.google.inject.Guice.createInjector(Guice.java:69)
	at com.google.inject.Guice.createInjector(Guice.java:59)
	at org.codehaus.plexus.DefaultPlexusContainer.addComponent(DefaultPlexusContainer.java:344)
	at org.codehaus.plexus.DefaultPlexusContainer.addComponent(DefaultPlexusContainer.java:332)
	at org.jetbrains.idea.maven.server.Maven3ServerEmbedderImpl.customizeComponents(Maven3ServerEmbedderImpl.java:555)
	at org.jetbrains.idea.maven.server.Maven3ServerEmbedderImpl.customize(Maven3ServerEmbedderImpl.java:529)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
    ... omit some log ...
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - IntelliJ IDEA 2017.1.6  Build #IU-171.4694.73 
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - JDK: 1.8.0_112 
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - VM: Java HotSpot(TM) 64-Bit Server VM 
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - Vendor: Oracle Corporation 
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - OS: Mac OS X 
2020-03-16 14:40:05,386 [13326908]  ERROR -      #org.jetbrains.idea.maven - Last Action: Maven.Reimport 

通过错误日志,我们可以知道到底出哪里出现了问题。

对于上述问题,实际上就是 Maven 的版本与 IntelliJ IDEA 的版本不兼容的问题。

解决方法

在本案例中,两者的版本分别为:

  • IntelliJ IDEA(2017.1.6
  • Maven(3.6.3

当我切换 Maven 的版本为3.2.5的时候,该问题解决。

maven-config
maven-config

说实话,无论是 IntelliJ IDEA 还是 Maven 版本更新的都比较快,想要找老版本有的安装包还真不太好找。

在此,给大家分享一个下载 Maven 各种版本的「仓库」,强烈推荐收藏

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多