Maven 专题(八):配置(一)常用修改配置

 修改配置文件

通常我们需要修改解压目录下conf/settings.xml文件,这样可以更好的适合我们的使用。

  • 此处注意:所有的修改一定要在注释标签外面,不然修改无效。Maven很多标签都是给的例子,都是注释掉的。

1. 本地仓库位置修改

在<localRepository>标签内添加自己的本地位置路径

复制代码; "复制代码")

<!-- localRepository | The path to the local repository maven will use to store artifacts. |
| Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository>
-->

<localRepository>D:\tools\repository</localRepository>

复制代码; "复制代码")

2. 修改maven默认的JDK版本

在<profiles>标签下添加一个<profile>标签,修改maven默认的JDK版本。

复制代码; "复制代码")

<profile>

<id>JDK-1.8</id>       
<activation>       
    <activeByDefault>true</activeByDefault>       
    <jdk>1.8</jdk>       
</activation>       
<properties>       
    <maven.compiler.source>1.8</maven.compiler.source>       
    <maven.compiler.target>1.8</maven.compiler.target>       
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>       
</properties>       

</profile>

复制代码; "复制代码")

3. 添加国内镜像源

添加<mirrors>标签下<mirror>,添加国内镜像源,这样下载jar包速度很快。默认的中央仓库有时候甚至连接不通。一般使用阿里云镜像库即可。这里我就都加上了,Maven会默认从这几个开始下载,没有的话就会去中央仓库了。

复制代码; "复制代码")

<!-- 阿里云仓库 -->
<mirror>

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

</mirror>

<!-- 中央仓库1 -->
<mirror>

<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>

</mirror>

<!-- 中央仓库2 -->
<mirror>

<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>

</mirror>

原文地址:https://www.cnblogs.com/hzcya1995/p/13309047.html