赞
踩
Maven是用Java语言写的项目管理工具
1、下载
http://maven.apache.org/download.cgi
这里我选择下载 apache-maven-3.8.4-bin.zip
2、解压
我的文件解压在 /Users/user/software/apache-maven-3.8.4
测试执行命令:
$ /Users/user/software/apache-maven-3.8.4/bin/mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /Users/user/software/apache-maven-3.8.4
Java version: 11.0.13, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
3、配置环境变量
PATH_MAVEN_HOME='/Users/user/software/apache-maven-3.8.4/bin'
export PATH=$PATH:$PATH_MAVEN_HOME
使生效
source ~/.bash_profile
测试:
$ mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
...
主要 修改文件:/Users/user/software/apache-maven-3.8.4/conf/settings.xml
关注 mirrors
, 添加阿里云 mirror,原来的不用动
<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>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
<!-- 阿里云 mirror -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
过去一些教程中,url 是 http://maven.aliyun.com/nexus/content/groups/public
,是老地址
可见 阿里云文档:https://developer.aliyun.com/mvn/guide
仓库名称 | 阿里云仓库地址 | 阿里云仓库地址(老版) | 源地址 |
---|---|---|---|
central | https://maven.aliyun.com/repository/central | https://maven.aliyun.com/nexus/content/repositories/central | https://repo1.maven.org/maven2/ |
public | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/groups/public | central仓和jcenter仓的聚合仓 |
gradle-plugin | https://maven.aliyun.com/repository/gradle-plugin | https://maven.aliyun.com/nexus/content/repositories/gradle-plugin | https://plugins.gradle.org/m2/ |
apache snapshots | https://maven.aliyun.com/repository/apache-snapshots | https://maven.aliyun.com/nexus/content/repositories/apache-snapshots | https://repository.apache.org/snapshots/ |
本地仓库的作用:存放项目的jar包,缓存库。
开发项目时项目首先会从本地仓库中获取 jar 包,当无法获取指定 jar 包的时候,本地仓库会从 远程仓库(或 中央仓库) 中下载 jar 包,并“缓存”到本地仓库中以备将来使用。
默认位于 ${user.home}/.m2/repository
, 在我的电脑即 /Users/user/.m2/repository
文件夹。
修改 localRepository
节点,如 我的 repo 创建在 /Users/user/Documents/repo_maven
文件夹。
<localRepository>/Users/user/Documents/repo_maven<localRepository>
执行下述命令,将会拉取数据到本地仓库
$ mvn help:system
[INFO] Scanning for projects...
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
...
第一次可能 BUILD FAILURE
, 再执行一次命令可能就可以了。
伊织 2021-12-01
十二月,让我对你好一点
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。