前言
Idea中已经自带了maven,但在使用自己下载的maven(V3.6.3),同时更改了本地默认仓库后发现,新建的maven项目中无法自动导入依赖。
正文
1.Maven下载安装及配置的修改
Maven的下载以及本地仓库和中央仓库的修改配置,网上教程众多,在此不再赘述,这里推荐一篇比较详细的Maven的安装教程——>传送门
首先介绍下,我的IDEA版本是2018.3,我下载的maven版本是3.6.3,maven安装目录是F:\Maven\apache-maven-3.6.3,本地仓库的位置为F:\Maven\apache-maven-3.6.3\repository,如下图所示。在配置好环境变量,通过使用mvn -v命令查看maven版本,来确认maven已经安装成功。
2. IDEA中创建Maven web项目
2.1修改IDEA中的Maven配置
下图是默认的Maven配置,根据自己本机中maven的安装位置进行修改,使用自己下载的3.6.3版本的Maven。
使用自己下载的maven,修改路径后单击OK,效果图如下:
2.2 创建Maven web项目
勾选 Create from archetype,即从模板中创建项目,选择maven-archetype-webapp,点击next
输入GroupId,ArtifactId后点击next
从下图中可以看出确实是使用我们自己下载的版本为3.6.3的Maven,使用的是自己的配置文件。继续next
设置项目的位置后点击finish
2.3 修改依赖jar包的版本
打开pom.xml文件,将junit的版本修改为最新的4.13时发现报错,提示查看log文件。
点击help下的show log in explorer
查看idea.log日志文件
2.3 找到对应时间下的错误日志如下,发现是两个错误。
- No implementation for org.apache.maven.model.path.PathTranslator was bound.
- No implementation for org.apache.maven.model.path.UrlNormalizer was bound.
2020-01-20 22:32:16,314 [7535702] ERROR - #org.jetbrains.idea.maven - IntelliJ IDEA 2018.3.6 Build #IU-183.6156.11
2020-01-20 22:32:16,315 [7535703] ERROR - #org.jetbrains.idea.maven - JDK: 1.8.0_152-release; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2020-01-20 22:32:16,315 [7535703] ERROR - #org.jetbrains.idea.maven - OS: Windows 10
2020-01-20 22:32:16,332 [7535720] ERROR - #org.jetbrains.idea.maven - Last Action: EditorBackSpace
2020-01-20 22:32:35,092 [7554480] 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:557)
at org.jetbrains.idea.maven.server.Maven3ServerEmbedderImpl.customize(Maven3ServerEmbedderImpl.java:527)
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)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
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)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy170.customize(Unknown Source)
at sun.reflect.GeneratedMethodAccessor854.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.execution.rmi.RemoteUtil.invokeRemote(RemoteUtil.java:179)
at com.intellij.execution.rmi.RemoteUtil.access$300(RemoteUtil.java:39)
at com.intellij.execution.rmi.RemoteUtil$2$1$1.compute(RemoteUtil.java:160)
at com.intellij.openapi.util.ClassLoaderUtil.runWithClassLoader(ClassLoaderUtil.java:66)
at com.intellij.execution.rmi.RemoteUtil.executeWithClassLoader(RemoteUtil.java:231)
at com.intellij.execution.rmi.RemoteUtil$2$1.invoke(RemoteUtil.java:157)
at com.sun.proxy.$Proxy170.customize(Unknown Source)
at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.doCustomize(MavenEmbedderWrapper.java:96)
at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.lambda$customizeForResolve$1(MavenEmbedderWrapper.java:69)
at org.jetbrains.idea.maven.server.RemoteObjectWrapper.perform(RemoteObjectWrapper.java:76)
at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.customizeForResolve(MavenEmbedderWrapper.java:68)
at org.jetbrains.idea.maven.project.MavenProjectsTree.resolve(MavenProjectsTree.java:1272)
at org.jetbrains.idea.maven.project.MavenProjectsProcessorResolvingTask.perform(MavenProjectsProcessorResolvingTask.java:45)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor.doProcessPendingTasks(MavenProjectsProcessor.java:134)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor.access$000(MavenProjectsProcessor.java:32)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor$2.run(MavenProjectsProcessor.java:109)
at org.jetbrains.idea.maven.utils.MavenUtil.lambda$runInBackground$5(MavenUtil.java:451)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
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-01-20 22:32:35,093 [7554481] ERROR - #org.jetbrains.idea.maven - IntelliJ IDEA 2018.3.6 Build #IU-183.6156.11
2020-01-20 22:32:35,093 [7554481] ERROR - #org.jetbrains.idea.maven - JDK: 1.8.0_152-release; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2020-01-20 22:32:35,094 [7554482] ERROR - #org.jetbrains.idea.maven - OS: Windows 10
2020-01-20 22:36:01,283 [7760671] WARN - gin.utils.ProfilingUtilAdapter - YourKit controller initialization failed : To profile application, you should run it with the profiler agent
2020-01-20 22:40:55,702 [8055090] INFO - ide.actions.ShowFilePathAction -
Exit code 1
3.解决方案:
由报错原因可知,是maven版本的兼容性问题,由于我的idea是2018.3.5,而下载的maven的版本是最新的3.6.3。此时可以换一个版本较低的Maven,即可解决此问题,因为我显重新下载一个Maven麻烦,因此直接在setting中修改使用了IDEA自带的低版本的maven,如下图,使用低版本3.3.9的maven后,最终成功解决自动导入依赖的问题。
[外链图片转存失败,源站可能有防盗在这里插入!链机制,建描述]议将图片上https://传(imbog.Vdnimg.cn/20200UysB120225458267.png?x-oss-process=image/watermark,type_ZupoZW9naGVpdGk,shadow_10,text_aHR0cHM5Ly9ibG9nLmNzZG4ubmV0L3FxXzQwNTYzNzYx,size_13,color_FFFFFF,t_70692)(https://img-blog.csdnimgcn/20200120225458267.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwNTYzNzYx,size_16,color_FFFFFF,t_70)]
可以看出junit已经成功修改为4.13的版本
最后需要注意我这里在是直接在settting中将maven换成idea自带的,只是对这一个项目的设置,如果你想新建其他的项目时也生效,需要在File——>Other Setting——>Setting for New Projects中对Maven的设置进行修改,把它的换成idea自带的低版本的maven。
后记
苦心人,天不负。卧薪尝胆,三千越甲可吞吴。