maven安装配置
大约 2 分钟
maven 安装配置
下载maven
maven 安装
解压
注意: Maven 下载后,将 Maven 解压到一个没有中文没有空格的路径下,比如 D:\maven 下面 解压后,有如下目录:
- bin:含有 mvn 运行的脚本
- boot:含有 plexus-classworlds 类加载器框架,Maven 使用该框架加载自己的类库。
- conf:含有 settings.xml 配置文件
- lib:含有 Maven 运行时所需要的 java 类库
环境变量
maven 依赖 java 环境,所以要确保 java 环境已配置好 使用 maven 必须配置 JDK。 在环境变量 path 配置 MAVEN 安装目录的 bin 目录(和之前 jdk 的配置类似)
测试
mvn -v
maven 配置
本地仓库
maven 的 conf 目录中有 settings.xml ,是 maven 的配置文件,做如下配置:
<localRepository>D:\Program Files\maven\myrepository</localRepository>
jdk 配置
<profiles>
<!-- 在已有的profiles标签中添加profile标签 -->
<profile>
<id>myjdk</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>
</profiles>
<!-- 让增加的 profile生效 -->
<activeProfiles>
<activeProfile>myjdk</activeProfile>
</activeProfiles>
完整配置如下
配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>D:\develop\pository\maven</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>maven</id>
<mirrorOf>*</mirrorOf>
<name>maven source</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyun-public</id>
<mirrorOf>*</mirrorOf>
<name>aliyun public</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>aliyun-central</id>
<mirrorOf>*</mirrorOf>
<name>aliyun central</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>aliyun-spring</id>
<mirrorOf>*</mirrorOf>
<name>aliyun spring</name>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>
<mirror>
<id>aliyun-spring-plugin</id>
<mirrorOf>*</mirrorOf>
<name>aliyun spring-plugin</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
</mirror>
<mirror>
<id>aliyun-apache-snapshots</id>
<mirrorOf>*</mirrorOf>
<name>aliyun apache-snapshots</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</mirror>
<mirror>
<id>aliyun-google</id>
<mirrorOf>*</mirrorOf>
<name>aliyun google</name>
<url>https://maven.aliyun.com/repository/google</url>
</mirror>
<mirror>
<id>aliyun-gradle-plugin</id>
<mirrorOf>*</mirrorOf>
<name>aliyun gradle-plugin</name>
<url>https://maven.aliyun.com/repository/gradle-plugin</url>
</mirror>
<mirror>
<id>aliyun-jcenter</id>
<mirrorOf>*</mirrorOf>
<name>aliyun jcenter</name>
<url>https://maven.aliyun.com/repository/jcenter</url>
</mirror>
<mirror>
<id>aliyun-releases</id>
<mirrorOf>*</mirrorOf>
<name>aliyun releases</name>
<url>https://maven.aliyun.com/repository/releases</url>
</mirror>
<mirror>
<id>aliyun-snapshots</id>
<mirrorOf>*</mirrorOf>
<name>aliyun snapshots</name>
<url>https://maven.aliyun.com/repository/snapshots</url>
</mirror>
<mirror>
<id>aliyun-grails-core</id>
<mirrorOf>*</mirrorOf>
<name>aliyun grails-core</name>
<url>https://maven.aliyun.com/repository/grails-core</url>
</mirror>
<mirror>
<id>aliyun-mapr-public</id>
<mirrorOf>*</mirrorOf>
<name>aliyun mapr-public</name>
<url>https://maven.aliyun.com/repository/mapr-public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk11</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>11</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>ali</id>
<repositories>
<repository>
<id>central-repos1</id>
<name>Central Repository 2</name>
<url>http://repo1.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jdk11</activeProfile>
<activeProfile>ali</activeProfile>
</activeProfiles>
</settings>