Brew安装Maven及其IDEA配置
安装Maven
brew提供了便捷的maven安装⽅式,并且⽬前在m1芯⽚的mac上,brew也会⾃动帮我们装上arm版本的软件(如果已经更新)。
% brew search maven
#使⽤搜索⼯具去搜索maven包
% brew info maven
#使⽤info查看maven包当前的信息情况,包括版本依赖描述等
maven: stable 3.8.4 (bottled)
Java-based project management
/
Conflicts with:
mvnvm (because also installs a 'mvn' executable)
/opt/homebrew/Cellar/maven/3.8.4 (79 files, 10MB) *idea配置artifacts
Poured from bottle on 2021-12-11 at 01:35:47
From: github/Homebrew/homebrew-core/blob/HEAD/Formula/maven.rb
License: Apache-2.0
==> Dependencies
Required: openjdk ✔
==> Analytics
install: 77,138 (30 days), 213,336 (90 days), 671,866 (365 days)
install-on-request: 76,660 (30 days), 211,765 (90 days), 667,184 (365 days)
build-error: 0 (30 days)
% brew install maven
#执⾏安装命令
Running `brew update --preinstall`...
==> Downloading ghcr.io/v2/homebrew/core/maven/manifests/3.8.4
>>>>>>>>>>>>>>## 100.0%
欧米茄constellation全钻价格==> Downloading ghcr.io/v2/homebrew/core/maven/blobs/sha256:6e032d44f0fef2a59373945e95b7f7522e4dc95069498b54fe9075d065883b5d
==> Downloading from pkg-containers.githubusercontent/ghcr1/blobs/sha256:6e032d44f0fef2a59373945e95b7f7522e4dc95069498b54fe9075d065883b5d?se=2021-12-10T17%3A45%3A00Z&sig=46FG2QGnp%2BipfJwRP8rl >>>>>>>>>>>>>>## 100.0%
==> Pouring maven--3.8.4.arm64_monterey.
/opt/homebrew/Cellar/maven/3.8.4: 79 files, 10MB
==> Running `brew cleanup maven`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
安装过程很顺利,这时候brew就已经帮我们做好了环境变量了。很多教程在这⼀步后会⼿动去⽣命maven的⽬录情况,我看了⼏个教程⾥⾯的设置完全没有道理,根本链接的不
是brew的安装位置。
% which mvn
# brew已经帮我们做过链接了,可以直接使⽤mvn命令
% mvn -vresizeable的参数设置为true
# 查看安装好的maven信息
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /opt/homebrew/Cellar/maven/3.8.4/libexec
Java version: 17.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "12.0.1", arch: "aarch64", family: "mac"
配置Maven
可以看到brew⾃动帮我装好了arm版本的maven,因为我是m1芯⽚。如果是x86的芯⽚,会帮你装x86版本,路径位置可能不同,但设置没啥区别,注意换成⾃⼰路径即可。我们
接下来看maven的配置⽂件位置。
上⾯maven信息输出中有Maven home: /opt/homebrew/Cellar/maven/3.8.4/libexec,冒号后⾯就是brew帮我们下载的安装⽬录。直接执⾏cd
/opt/homebrew/Cellar/maven/3.8.4/libexec,进⼊⽬录。
% cd /opt/homebrew/Cellar/maven/3.8.4/libexec
% ls
logging  l
# 看到了熟悉的setting⽂件
在xml⽂件中,我们要关注两个地⽅,我在下⾯列了出来localRepository和mirrors。第⼀个localRepository是你本地仓库所在的位置,你的包都会下载到这⾥,默认在你⽤户⽬录
的.m2⽬录下,我觉得挺直观的,就没修改了,这⾥可以换成你想存放的地址。第⼆个mirror是你的包下载地址,因为有墙,所以建议增加阿⾥云仓库配置,来加速下载。具体配
置如下,可以⾃⼰在xml中寻。
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
java环境变量配置检测<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>my.repository/repo/path</url>
</mirror>
-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿⾥云公共仓库</name>
<url>maven.aliyun/repository/public</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>0.0.0.0/</url>
flash get是什么<blocked>true</blocked>
unix是不是网络操作系统
</mirror>
</mirrors>
到这⾥,我们的maven已经安装完毕。仓库位置在我们本地⽤户⽬录下的.m2中,maven安装位置为之前的maven home。我们开始为IDEA配置本地maven环境。
IDEA的Maven配置
我们打开idea的偏好设置,搜索maven,出现以下的配置界⾯。
我们将安装⽬录和配置⽬录替换成配置maven时确定的路径,不好通过访达选⽂件就直接把路径复制填上去,应⽤保存即可。到这⾥就⼤功告成了!

发表评论