其他资源
1.MavenRepository:Maven Repository: Search/Browse/Explore (mvnrepository.com)
通过他,我们能查找Maven中央仓库具有的依赖坐标,从而导入使用它。
Maven和jdk对应的版本
作者,我这里 jdk14 使用不了 maven3.8 以上的版本
1.下载和安装
1.点击进入MavenMaven – Welcome to Apache Maven
2.如下图,windows要下载的zip包。
3.之后点击下载解压到你安装的目录,我是放到了D盘。
D:\tools\apache-maven-3.6.1
2.配置环境变量
其实用户变量和全局变量没啥区别,就是权限区别。
参考我下面那张图:
M2_HOME 你的Maven安装目录(MAVEN_HOME也可以)
之后,打开控制台 输入 mvn -v
安装成功了!
3.Maven配置多仓库
maven仓库在国外,我们的依赖下载是非常慢的,所以要用到国内镜像库,但是有些依赖镜像库是没有的,又必须从中央仓库下载。
我建议
这里我配置的是阿里云的镜像库。
建议本地仓库安装在你的Maven的安装包里,这样好找。
1.配置本地仓库
就是上图仓库的路径
<!-- 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/apache-maven-3.6.1/repository</localRepository>
2. 配置镜像库
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!--阿里镜像的配置-->
<mirror>
<id>aliyun</id>
<mirrorOf>central</mirrorOf>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
3.配置中央仓库
这一堆是在<profiles></profiles>里面。
<profile>
<id>gf</id>
<repositories>
<repository>
<id>maven-default</id>
<!-- 注意这个http要带s,不然访问不到,我看很多都没带,所以访问不了。 -->
<url>https://repo1.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>jdk-14</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>14</jdk>
</activation>
<properties>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<maven.compiler.compilerVersion>14</maven.compiler.compilerVersion>
</properties>
</profile>
4.最后一个看下图。
<activeProfiles>
<activeProfile>aliyun</activeProfile>
<activeProfile>gf</activeProfile>
</activeProfiles>