当前位置:   article > 正文

macOS - Maven 安装配置_macos 配置maven

macos 配置maven

在这里插入图片描述


Maven是用Java语言写的项目管理工具

主页:http://maven.apache.org


安装

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"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3、配置环境变量

PATH_MAVEN_HOME='/Users/user/software/apache-maven-3.8.4/bin'
export PATH=$PATH:$PATH_MAVEN_HOME
  • 1
  • 2

使生效

source ~/.bash_profile
  • 1

测试:

$ mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
...
  • 1
  • 2
  • 3

配置

主要 修改文件:/Users/user/software/apache-maven-3.8.4/conf/settings.xml

1、国内镜像

关注 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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

过去一些教程中,url 是 http://maven.aliyun.com/nexus/content/groups/public,是老地址
可见 阿里云文档:https://developer.aliyun.com/mvn/guide

仓库名称阿里云仓库地址阿里云仓库地址(老版)源地址
centralhttps://maven.aliyun.com/repository/centralhttps://maven.aliyun.com/nexus/content/repositories/centralhttps://repo1.maven.org/maven2/
publichttps://maven.aliyun.com/repository/publichttps://maven.aliyun.com/nexus/content/groups/publiccentral仓和jcenter仓的聚合仓
gradle-pluginhttps://maven.aliyun.com/repository/gradle-pluginhttps://maven.aliyun.com/nexus/content/repositories/gradle-pluginhttps://plugins.gradle.org/m2/
apache snapshotshttps://maven.aliyun.com/repository/apache-snapshotshttps://maven.aliyun.com/nexus/content/repositories/apache-snapshotshttps://repository.apache.org/snapshots/

2、配置本地仓库

本地仓库的作用:存放项目的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>
  • 1

拉取包

执行下述命令,将会拉取数据到本地仓库

$ 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
...
  • 1
  • 2
  • 3
  • 4

第一次可能 BUILD FAILURE, 再执行一次命令可能就可以了。


伊织 2021-12-01
十二月,让我对你好一点

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号