IDEA新建Maven项目时报错

IDEA新建Maven项目时报错

IDEA新建Maven项目时报错

E:\Java\jdk1.7.0_80\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\job012\AppData\Local\Temp\archetype1tmp "-Dmaven.home=E:\IntelliJ IDEA 2018.3.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=E:\IntelliJ IDEA 2018.3.1\plugins\maven\lib\maven3\bin\m2.conf" -Dfile.encoding=UTF-8 -classpath "E:\IntelliJ IDEA 2018.3.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.3.1 -DinteractiveMode=false -DgroupId=SpringDemo1 -DartifactId=SpringDemo1 -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.cocoon -DarchetypeArtifactId=cocoon-22-archetype-webapp -DarchetypeVersion=RELEASE org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins:maven-archetype-plugin/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.975 s
[INFO] Finished at: 2018-12-13T11:36:19+08:00
[INFO] Final Memory: 7M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-archetype-plugin:RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-archetype-plugin:jar:RELEASE: Failed to resolve version for org.apache.maven.plugins:maven-archetype-plugin:jar:RELEASE: Could not find metadata org.apache.maven.plugins:maven-archetype-plugin/maven-metadata.xml in local (C:\Users\job012\.m2\repository) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
[ERROR] Maven execution terminated abnormally (exit code 1)

 

 出错的项目结构: 

 

 

IDEA新建Maven项目时报错

正确的项目结构:

IDEA新建Maven项目时报错

问题和解决方案

idea的maven一开始是没有setting.xml的,你要去maven的目录里面拷一份setting.xml到你的仓库中。idea的maven在安装路径的plugins文件夹下,即X:\xxx\JetBrains\IntelliJ IDEA 2016.3.2\plugins\plugins\maven\lib\maven3\conf\setting.xml拷贝到你的用户文件夹下的.m2文件夹下,为了之后能够快速的下载依赖包,我们要加一个官方库的镜像,因为maven的官方仓库在国外,太慢了。 
在你的.m2文件夹下的setting.xml中添加如下代码:

<mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

IDEA新建Maven项目时报错

这个是阿里的库,所以很快。做完之后我们回到idea,点击next,然后填写项目名,然后finish。 
接下来idea开始创建项目,这里你要把maven自动导入打开。

IDEA新建Maven项目时报错

IDEA新建Maven项目时报错

参考博文:

https://www.cnblogs.com/shang-shang/p/7477607.html