Maven学习文档

160 阅读1分钟

Maven

官网下载地址Maven – Download Apache Maven

具体下载地址:dlcdn.apache.org/maven/maven…

注意,不同版本的IEDA需要下载对应版本的Maven

  • [0.IDEA 2022 兼容maven 3.8.1及之前的所用版本]
  • [1.IDEA 2021 兼容maven 3.8.1及之前的所用版本]
  • [2.IDEA 2020 兼容Maven 3.6.3及之前所有版本]
  • [3.IDEA 2018 兼容Maven3.6.1及之前所有版本]

注意:全程路径需要使用一个非中文、没有空格的目录。

  • 在解压目录中,我们需要着重关注 Maven 的核心配置文件:conf/settings.xml

指定本地仓库

记住:一定要把 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:\JAVA\maven\maven-repo</localRepository>

配置阿里云提供的镜像仓库

maven.aliyun.com/nexus/conte…

 <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>nexus-aliyun</id>
		<mirrorOf>central</mirrorOf>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>
	 
  </mirrors>

配置 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>

配置环境变量

MAVEN_HOME

path:%MAVEN_HOME%\bin

验证

C:\Users\King‘sLanding>mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: D:\JAVA\maven\apache-maven-3.6.1\bin\..
Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: D:\JAVA\jdk1.8.0_131\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

C:\Users\King‘sLanding>

## IEDA中创建Maven

第四章 使用Maven:IDEA环境 | 代码重工 (gitee.io)

每次创建 Project 后都需要设置 Maven 家目录位置,否则 IDEA 将使用内置的 Maven 核心程序(不稳定)并使用默认的本地仓库位置。这样一来,我们在命令行操作过程中已下载好的 jar 包就白下载了,默认的本地仓库通常在 C 盘,还影响系统运行。

image-20220731145741516.png