环境介绍:
Windows10专业版、IDEA2020.1、Maven3.6.3、Java11
IDEA2020.1下载地址:https://www.jetbrains.com/ 官网下载对应版本即可
Maven3.6.3下载地址:http://maven.apache.org/download.cgi 官网下载对应版本即可
Maven安装后配置环境变量:
如果你想在本地安装多个版本的Maven,可以使用如图的方式,分别定义对应版本的变量名,然后MAVEN_HOME指向你需要使用版本的变量名即可,如果只安装一个版本则直接在MAVEN_HOME变量名中指定其变量值即可。
修改Maven安装目录${MAVEN_HOME}\conf\setting.xml
示例(3.6.3为例):
在<mirrors></mirrors>标签中添加在如下:
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
在<profiles></profiles>标签中添加如下(使用的JDK1.8):
<profile>
<id>jdk-11</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>11</jdk>
</activation>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
</properties>
</profile>
在<settings></settings>标签中添加本地仓库目录:
<localRepository>E:\ProgramData\.m2_maven\repository</localRepository>
注意:如果你使用的是Java11及以上的环境,那么
标签<localRepository></localRepository>不再需要配置了,在IDEA中使用时在指定对应的本地仓库目录
IDEA(2020.1)中配置Maven3.6.3:
这里对应前面的注意部分
重点来了
需要配置如上两图部分的VM Options:
-Xmx768m -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true
否则IDEA在新建Maven项目时会报错:
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 (E:\ProgramData\.m2_maven\repository) -> [Help 1
如果IDEA在新建Maven项目后下载对应插件时报警告:
No archetype found in remote catalog. Defaulting to internal catalog
只需要在新建项目时添加一个变量即可(不过只是报警告,不理会也没关系)
这面往后的新建项目就不会有任何错误和警告了。